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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to