using empty on inaccessible object with __isset and __get

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2012-10-19T22:45:28Z Indexed on 2012/10/19 23:01 UTC
Read the original article Hit count: 186

Filed under:
|
|
<?php

class Magic_Methods
{
    protected $meta;

    public function __construct() 
    {
        $this->meta = (object) array(
            'test' => 1
        );
    }

    public function __isset($name) 
    {
        echo "pass isset {$name} \n";

        return isset($this->$name);
    }

    public function __get($name) 
    {
        echo "pass get {$name} \n";

        return $this->$name;
    }
}

$mm = new Magic_Methods();

$meta = empty($mm->meta->notExisting);

var_dump($meta);

echo "||\n";

$meta = empty($mm->meta);

var_dump($meta);

The snippet above does not work as expected for me. Why would the first empty() ommit the __isset? I get this:

pass get meta 
bool(true)
||
pass isset meta 
pass get meta 
bool(false)

I would expected identical results or another pass at the __isset, but not a direct call to __get. Or am I missing something here?

© Stack Overflow or respective owner

Related posts about php

Related posts about getter