note 87964 added to class.arrayobject

From: Date: Fri, 02 Jan 2009 21:31:50 +0000
Subject: note 87964 added to class.arrayobject
Groups: php.notes 
Request: Send a blank email to php-notes+get-148768@lists.php.net to get a copy of this message
Generally variable $this can't be used as an array within an object context. For example, following code piece would cause a fatal error: <?php class TestThis { public function __set($name, $val) { $this[$name] = $val; } public function __get($name) { return $this[$name]; } } $obj = new TestThis(); $obj->a = 'aaa'; echo $obj->a . "\n"; ?> But things are different when $this is used in an ArrayObject object. e.g., following code piece are valid: <?php class TestArrayObject extends ArrayObject { public function __set($name, $val) { $this[$name] = $val; } public function __get($name) { return $this[$name]; } } $obj = new TestArrayObject(); $obj->a = 'aaa'; echo $obj->a . "\n"; ?> ---- Server IP: 209.41.74.194 Probable Submitter: 208.67.191.194 ---- Manual Page -- http://www.php.net/manual/en/class.arrayobject.php Edit -- https://master.php.net/note/edit/87964 Del: integrated -- https://master.php.net/note/delete/87964/integrated Del: useless -- https://master.php.net/note/delete/87964/useless Del: bad code -- https://master.php.net/note/delete/87964/bad+code Del: spam -- https://master.php.net/note/delete/87964/spam Del: non-english -- https://master.php.net/note/delete/87964/non-english Del: in docs -- https://master.php.net/note/delete/87964/in+docs Del: other reasons-- https://master.php.net/note/delete/87964 Reject -- https://master.php.net/note/reject/87964 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148768) next »