I would like to do something like:
function func($var1 = 'Hello', $var2 = "{$var1} World") { echo $var2; }
This is not possible!
My idea is to avoid extra code lines inside my function but I don’t know if that is possible.
Does someone know if a similar procedure is possible in php?
Thanks.
Like the other answers say, you can’t do this directly in PHP. My solution to these situations is usually to mimic the behaviour using something like this
But the big downside is you’re copying PHP behaviour so you’ll have to throw your own exceptions when variables are forgotten, the wrong type etc.