Como usar __get () para retornar null em acessos de propriedade de objeto multinível?

Como posso usar __get () para retornar null na propriedade de objeto multinível acessando o caso como este abaixo?

Por exemplo, esta é minhas aulas,

<code>class property 
{

    public function __get($name)
    {
        return (isset($this->$name)) ? $this->$name : null;
    }
}


class objectify
{

    public function array_to_object($array = array(), $property_overloading = false)
    {
        # if $array is not an array, let's make it array with one value of former $array.
        if (!is_array($array)) $array = array($array);

        # Use property overloading to handle inaccessible properties, if overloading is set to be true.
        # Else use std object.
        if($property_overloading === true) $object = new property();
            else $object = new stdClass();

        foreach($array as $key => $value)
        {
            $key = (string) $key ;
            $object->$key = is_array($value) ? self::array_to_object($value, $property_overloading) : $value;
        }


        return $object;

    }
}
</code>

Como eu uso,

<code>$object = new objectify();

$type = array(
    "category"  => "admin",
    "person"    => "unique",
    "a"         => array(
        "aa" => "xx",
        "bb"=> "yy"
    ),
    "passcode"  => false
);


$type = $object->array_to_object($type,true);
var_dump($type->a->cc);
</code>

resultado,

<code>null
</code>

mas eu recebo uma mensagem de erro com NULL quando a matriz de entrada énull,

<code>$type = null;
$type = $object->array_to_object($type,true);
var_dump($type->a->cc);
</code>

resultado,

<code>Notice: Trying to get property of non-object in C:\wamp\www\test...p on line 68
NULL
</code>

É possível retornar NULL nesse tipo de cenário?

questionAnswers(3)

yourAnswerToTheQuestion