Mantis - Quercus
Viewing Issue Advanced Details
3141 major always 12-10-08 01:57 01-09-09 21:10
mattsecrett  
nam  
normal  
closed 3.2.1  
fixed  
none    
none 4.0.0  
0003141: __get() not firing on $object->objects["name"]->value

Hi,

Not sure if this is me doing something wrong, but if I have an object that has an array of objects, and I try to access a member variable of one of the child objects, using the format $object->objects["name"]->value, it returns nothing. If, however, I use $object->objects["name"]->__get("value"), it correctly returns the value. See test code below for example.

Thanks,

Matt

-------------------------------

class Test
{
    private $_values;

    public function __construct()
    {
        $this->_values = array();
    }

    public function __get($field)
    {
        return $this->_values[$field];
    }

    public function __set($field, $value)
    {
        $this->_values[$field] = $value;
        return true;
    }

    public function display($value)
    {
        echo "Here it is: $value
";
    }
}

function testResin()
{
    $test1 = new Test();

    $test1->fields = array();
    $test1->fields["field1"] = new Test();
    $test1->fields["field1"]->value = "I am field 1";

    $test2 = new Test();
    $test2->display($test1->fields["field1"]->value); // this fails
    $test2->display($test1->fields["field1"]->__get("value")); //this works
}
 quercus_ArgGetValue.zip [^] (3,427 bytes) 01-09-09 07:59

Notes
(0003710)
haplo   
01-09-09 08:06   
The problem is that the function arguments are not resolved correctly.

If you use a method chain like $this->MagicGetOne->MagicGetTwo as a function argument quercus tries to get the Field MagicGetTwo from the $this->MagicGetOne but it does not execute the $this->MagicGetOne statement correctly.

I attached a fix. Just put the zip files into com.caucho.quercus.env package.

BTW:
Change the line
    $test2->display($test1->fields["field1"]->value);
to
    $test2->display($result = $test1->fields["field1"]->value);
this should work
(0003717)
nam   
01-09-09 21:10   
php/09kr
php/39kr