Re: [PROPOSAL] Change (just slightly) read/write_property() and get_property_ptr_ptr() usage

From: Date: Mon, 19 Feb 2007 11:31:52 +0000
Subject: Re: [PROPOSAL] Change (just slightly) read/write_property() and get_property_ptr_ptr() usage
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-28069@lists.php.net to get a copy of this message
On 02/19/2007 02:23 PM, Peter Hodge wrote:
Hello, Does that fix the problem where: $object->theArray[] = (...); is invalid when 'theArray' is implemented using __get()? Whoever fixes that one could get all free drinks at PHP conferences: PHP Hacker: "Hi, I'm the guy who made it so you can add items to an array which is returned through __get()" PHP Fanboy: "Dude that is so awesome, how could I ever repay you!? Can I buy you a beer?"
I believe you can start buying drinks for Dmitry =) This code: <?php class test { private $var = array(); function &__get($name) { /* note the & */
       return $this->$name;
} } $t = new test; $t->var[] = "first"; $t->var[][] = "second"; $t->var[][][] = "third"; var_dump($t); ?> produces the following output: object(test)#1 (1) { ["var:private"]=> array(3) { [0]=> string(5) "first" [1]=> array(1) {
     [0]=>
     string(6) "second"
} [2]=> array(1) {
     [0]=>
     array(1) {
       [0]=>
       string(5) "third"
     }
} } } -- Wbr, Antony Dovgal

« previous php.internals (#28069) next »