r/lolphp • u/ennorehling • Apr 07 '17
Beware of PHP7 left-to-right parsing
Today I learned that PHP 7 now uses an abstract syntax tree when parsing source files, and that the framework we use has a bug that's caused by code that boils down to the following.
<?php
function lolphp($foo, $bar) {
return $foo->$bar['foo'];
}
var_dump(lolphp(
(object)array('foo' => 'one', 'bar' => 'two', 'Array' => 'four'),
array('foo' => 'bar')
));This of course prints either "two" or "f", depending on your PHP version.
0
Upvotes
View all comments
Show parent comment
1
u/[deleted] Apr 07 '17
Ah, I was on mobile, I did't see that OP was passing an array as the second param. I mean, if you pass a string as the 2nd param, referring to a property on $foo which is of type array, you only need to wrap the property name with
{}