There is no expression language in PHP, but you can use the operator .
to concatenate Strings.
Try this:
function func($var1 = 'Hello', $var2 = ' Worls') { echo $var1.$var2; }
No, you can't use it in the function parameter. Why would you want that? Just do it in the body function. It's better if there is no logic in the function parameters. More clear, more legible, more maintenable.
Also is not nice in terms of performance. You are creating a depencency between $var1
default value and $var2
default value. The processor could be assigning the default values in reverse order for whatever reason (mostly optimization) but since you introduced a dependency, it cannot be done any more, so the processor has to wait until $var1
is resolved to be able to assign $var2
. Get it?
Anyway, the language thas not allow you to do it. But at least now you can have a possible reason of why (totally my assumption, I'm sure there are more different reasons for it).