4 ms·
Resolving arrays like that causes parse errors in a range of contexts. Anything that is a "function" cannot also pick one array key... leaving a lot of XML-pars
by gburt 15y ago
Resolving arrays like that causes parse errors in a range of contexts. Anything that is a "function" cannot also pick one array key... leaving a lot of XML-parsing code that looks like
$xml = getXpathWhatever();
$xml = $xml[0];
Stranger yet, is that it works perfectly fine with resolving objects... for example
$xml = funct()->something->somethingelse()->a
Works fine...
- birken 15y agoArray brackets after function calls are fixed in PHP 5.4: ~/php_source/php-src-5.3$ ./sapi/cli/php -r "function a() { return array(1,2); } print a()[0];" Parse error: syntax error, unexpected '[' in Command line code on line 1 ~/php_source/php-src-5.4$ ./sapi/cli/php -r "function a() { return array(1,2); } print a()[0];" 1
- z92 15y agoI usually write it as $xml = reset(getXpathWhatever()); which returns the first element from array.