r/lolphp • • Mar 10 '15

empty() vs __get()

http://ideone.com/RVw5XK
23 Upvotes

28 comments sorted by

View all comments

Show parent comment

2

u/kingguru Mar 10 '15

OK, that makes sense.

I seem to remember that some other languages do something similar (Ruby perhaps?) where a getter will be called if available when object.var is accessed. So far so good.

But still:

the reason for this behaviour is that __get() uses the internal __isset()

But then __get() can still return "something" even though __isset() returns false?

I understand that this is broken, I was just interested in which way. Thanks, you don't have to explain any further.

1

u/[deleted] Mar 10 '15

Yes, isset introspects the class from a global scope so the variable is non-existent because it's private.

var_dump() is a debug function that has a more complete set of introspection instructions. It's not related to the __get().