3 ms·
Is there any reason for this: "If a function returns an array, you have to assign it to a variable before accessing an element, you can't just add an index afte
by dfox 16y ago
Is there any reason for this: "If a function returns an array, you have to assign it to a variable before accessing an element, you can't just add an index after the function call." ? I cannot grasp why PHP's authors "designed" it this way.
- troels 16y agoPHP's parser/syntax is a bit of a mess. I'm guessing it could incur some sort of inconsistency.
- randallsquared 16y agoYeah, this is one of the most annoying things about PHP for me. Another similar one is that you can't use empty() on the result of a function call without assigning it to a variable first, and the error you get is something about an invalid write context, which is pretty opaque if you don't just happen to know what it means already.
- shaunxcode 16y agoOne trick is to return an (object)array('a' => 1, 'b' => 2) and then you can do $func($x)->a.