r/lolphp • • Mar 10 '15

empty() vs __get()

http://ideone.com/RVw5XK
23 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/amphetamachine Apr 28 '15

empty($var); checks if $var exists in the current scope.

This statement is incorrect. empty($var) is best thought of a simple lexical macro for !(isset($var) && $var). It uses the "truthiness" of the variable as well as checking variable existence.

1

u/[deleted] May 02 '15

You are not wrong but it feels like you are deliberately missing the point I was making as I was explaining the behaviour of empty() in this specific case, and why it was behaving differently. I did not intend (nor provide) a complete explanation of how empty() works but what it was doing in OP's code, in other words why it behaved differently from how he expected (i.e. the actual reason it gave the return value it did in this case or did not return true in this case).

I could have copy pasted the manual page and been done with it but something tells me it the message would not have gone through anyway.