Re: Overloading Limitation- Can Someone Confirm?
| From: | Jasper Bryant-Greene | Date: | Thu, 30 Mar 2006 12:31:40 +0000 |
| Subject: | Re: Overloading Limitation- Can Someone Confirm? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-232915@lists.php.net to get a copy of this message | ||
Chris wrote:
class testClass {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?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();
$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'])) {you just removed b from the array under 'arr' in the $vars member array.unset($tc->arr['b']);}
//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@album.co.nz 021 708 334