View Single Post
Old 06-18-2006, 03:38 PM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
__set, __get, etc. have a bug "by design"
PHP Code:
class a
{
    private 
$data = array();
    public function 
__set($key$val)
    {
        echo 
"a sets $key to $val";
        
$this->data[$key] = $val;
    }
}

class 
b
{
    public function 
foo()
    {
        echo 
$this->val;
    }
}

$a = new a();
$a->= new b();
$a->b->'foobar'// error 
That's why my above script puts objects in public and variables in the protected $data.

Same bug happens on arrays
PHP Code:
$a = new a();
$a->= array('entry');
echo 
$a->b[0]; // error 
DJMaze is offline   Reply With Quote