Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't end(( )) throw a strict notice? [duplicate]

Tags:

php

end(array_keys(array(0))) says PHP Strict standards: Only variables should be passed by reference ( http://3v4l.org/CNLVT )

end((array_keys(array(0)))) on the other hand, just works ( http://3v4l.org/168fi ). Why?

The VLD decompiler shows the same opcodes being ran the only difference is in the ext column but I can't find documentation on what that means.

like image 509
chx Avatar asked Oct 31 '22 23:10

chx


1 Answers

What's likely happening is array_keys is passing the result back by reference. As such, PHP is throwing you a notice that you shouldn't do that.

Wrapping in parenthesis actually changes the reference and forces PHP to evaluate the statement inside first. As such, it removes the reference. One of those weird things that doesn't look like it makes a difference but actually does.

More on the weirdness here http://phpsadness.com/sad/51

like image 70
Machavity Avatar answered Nov 10 '22 19:11

Machavity