In Perl, if I want to default a value that might exist, for example as a passed in parameter, I can do this:
$var = parm->('variable') || 'default';
Is there something analogous in PHP or do I have to check the value after assigning, and if it is still null assign it the default value?
Not exactly.
PHP 5.3 introduced what they call “the ternary shortcut”.
Which isn’t even that much of a shortcut and only works short-circuit-able values (if
0is a valid value for$foothis shortcut will fail.)Otherwise you’ll have to do the type/existence checking the old, hard, manual way.
You can also specify default values for parameters in the signature – not sure if that’s exactly what you’re getting at but here’s that in action