I would like to have a PHP function which accepts a parameter A, which I have given the type hint callable. Trouble is in some situations I would like to be able to pass NULL or something like that, …
Tag: default-value
PHP variable “default value”
I want to get a value from the session, but use a default if it is not defined. And ofcourse I want to circumvent the PHP notice. You can write a function that does this Example in action Is there a way to do this without defining this function in every file? Answer From PHP 7, you can now use
Best way to give a variable a default value (simulate Perl ||, ||= )
I love doing this sort of thing in Perl: $foo = $bar || $baz to assign $baz to $foo if $bar is empty or undefined. You also have $foo ||= $bletch which will only assign $bletch to $foo if $foo is not defined or empty. The ternary operator in this situation is tedious and tiresome. Surely there’s a simple, elegant