Re: __get() not reentrant?

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

 



Christopher J. Bottaro wrote:
Maybe I'm using "reentrant" incorrectly, but here is what I mean...

class Test  {
   function __get($nm)  {
      if ($nm == 'x')
         return $this->func();
      elseif ($nm == 'y')
         return 'y';
      elseif ($nm == 'xx')
         return 'x';
   }
   function func()   {
      return $this->xx;
   }
}
$t = new Test();
print $t->y . "\n";
print $t->xx . "\n";
print $t->x . "\n";
print $t->func() . "\n";

I would expect the following code to output:
y
x
x
x

But instead, it outputs:
y
x

x

Is this a bug? This limitation is not documented (maybe it should be?).

its not a bug, I believe its documented somewhere how this works. bottom line __get() does not work from 'inside' the class/object, so do something like instead:

     function func()   {
       return $this->__get('xx');
     }

which may not please the soul, but does work ;-)


-- C


-- 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