Re: Overloading Limitation- Can Someone Confirm?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris wrote:
class testClass
{
    public $vars = array();

    public function __get($key)
    {
return array_key_exists($key, $this->vars) ? $this->vars[$key] : null;
    }

    public function __set($key, $value)
    {
        $this->vars[$key] = $value;
    }

    public function __isset($key)
    {
        return array_key_exists($key, $this->vars);
    }

    public function __unset($key)
    {
        unset($this->vars[$key]);
    }
}


$tc = new testClass();

$tc->arr = array();

here you store an empty array in the $vars member array, under the key 'arr' (due to your magic methods). is that what you intended?

$tc->arr['a'] = 'A';
$tc->arr['b'] = 'B';

now you are adding elements to this array under the 'arr' key in the $vars member array.

if (isset($tc->arr['b'])) {
    unset($tc->arr['b']);
}

you just removed b from the array under 'arr' in the $vars member array.

//var_dump is only to see results of above
var_dump($tc);

this should show something equiv. to:

array(
	'arr'	=> array(
		'a' => 'A'
	)
)

what does it actually show?

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/     0800 4 ALBUM
jasper@xxxxxxxxxxx          021 708 334

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux