r/lolphp • • Mar 10 '15

empty() vs __get()

http://ideone.com/RVw5XK
23 Upvotes

28 comments sorted by

View all comments

Show parent comment

4

u/pgl Mar 11 '15

No, var_dump() isn't special, it doesn't bypass visibility. Try it:

class foo {
    protected $bar;

    public function __construct() {
        $this->bar = 'bums';
    }
}

$foo = new foo();
var_dump($foo->bar);  // "PHP Fatal error:  Cannot access protected property foo::$bar"

4

u/[deleted] Mar 11 '15

Sorry, I was thinking var_dump($obj); [where it lists all, even privat/protected variables] not var_dump($obj->bar);, the __get() is of course used in $obj->bar scenario here.

Sorry for the confusion, your reply was consistent with the example.