On 18 August 2024 05:46:09 BST, Mike Schinkel <m...@newclarity.net> wrote:
>I know that those functions can be called as a function and return a value
>like the following:
>
>$return_value = include($path);
You are right that it has a return value, but wrong to put its argument in
parentheses. This will *not* do what you expect:
$success = include($path) && somethingElse();
Because include is not actually a function, what is evaluated is `$path &&
somethingElse()`, then either `include true` or `include false` (which will of
course fail).
You instead need to write this:
$success = (include $path) && somethingElse();
I thought I'd added this example to the manual, but now can't find it.
Consequently, we can't just define optional parameters like we would a normal
function. We *could* extend the syntax to allow "include $path, $whatever;" but
it probably wouldn't feel very natural. It would be a syntax error to write
"include($path, $whatever)" just as "echo $foo, $bar" is valid, but "echo($foo,
$bar)" is not.
Regards,
Rowan Tommins
[IMSoP]