Re:What are the crawling horrors of PHP?
by dfox on Tuesday July 13, 2010 @07:25AM
(#1511007)
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.
[ Parent
| on HN ]
Re:What are the crawling horrors of PHP?
by shaunxcode on Tuesday July 13, 2010 @12:35PM
(#1511874)
One trick is to return an (object)array('a' => 1, 'b' => 2) and then you can do $func($x)->a.
PHP's parser/syntax is a bit of a mess. I'm guessing it could incur some sort of inconsistency.
Re:What are the crawling horrors of PHP?
by randallsquared on Tuesday July 13, 2010 @10:22AM
(#1511436)
Yeah, 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.