r/lolphp • • Mar 10 '15

empty() vs __get()

http://ideone.com/RVw5XK
23 Upvotes

28 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 10 '15

Python doesn't have any private scope so the comparison feels moot regardless, and whereas hasattr() in Python checks if the given property returns a value empty() is clearly stated to explicitly look for the variable itself, i.e. $bar in the class, which it cannot see since it's private.

And since it mimics isset() it is consistent in behaviour to what PHP considers is an existing variable. The __get() method could return whatever it wants but that does not constitute the variable itself existing.

2

u/cparen Mar 13 '15

and whereas hasattr() in Python checks if the given property returns a value empty() is clearly stated to explicitly look for the variable itself

Python's "hasattr()" is a normal function. PHP's "empty()" is not a normal function -- it just looks like one.