We all know calls like this:
list($a, $b) = explode(':', 'A:B');
But how to make a custom function that can be use the same way?
$obj->mylist($a, $b) = explode(':', 'A:B');
mylist($a, $b) = explode(':', 'A:B');
If i use the above lines of code i always get: “Can’t use method return value in write context in […]”
How to define the function / class method to accept that type of assignment? How to the the array returned by explode()? Via func_get_args()?
Sure, there are other ways to assign the result of explode(), but that is not the subject of this question. E.g.
$obj->mylist($a, $b, explode(':', 'A:B'));
mylist($a, $b, explode(':', 'A:B'));
It is impossible as you cannot write a method that can be used as an lvalue.
list()is not a function but a language construct, that’s why it can be used in the way it’s used.