On Sun, Aug 31, 2008 at 11:03 AM, Marcus Boerger <[EMAIL PROTECTED]> wrote: > Hello Diogo, > > Sunday, August 31, 2008, 12:50:15 AM, you wrote: > >> Exactly... > >> Is that normal workings or more like a bugie one? > >> On Sat, Aug 30, 2008 at 10:02 PM, Rasmus Lerdorf <[EMAIL PROTECTED]> wrote: >>> Cristian Rodríguez wrote: >>>> >>>> Diogo Neves escribió: >>>>> >>>>> Hi all, >>>>> >>>>> I'm emailling to ask why __call isn't called when you call a private >>>>> method from outside of function... >>>> >>>> Please provide example code ;-) >>> >>> He means this: >>> >>> class foo { >>> private function bar() { } >>> function __call($f,$a) { >>> echo "called $f"; >>> } >>> } >>> $a = new foo; >>> $a->bar(); >>> > > In the above code you clearly try to call a private method.
As Mike Lively before point to me __get, and after i tried __set, works diferently as u can see: <?php class foo { private $a = 'a'; public function __set( $name, $value ) { return $this->$name = $value; } public function __get( $name ) { return $this->$name; } } $obj = new foo; $obj->a = 'b'; echo( $obj->a ); ?> My problem was that i only had work with __get and expected same behavior for __call :) There is > nothing more to say. In the following case it coul dbe a bit different: > > <?php > class foo { > private function test() { > echo __METHOD__ . "\n"; > } > } > class bar extends foo { > function __call($name, $args) { > echo __METHOD__ . "($name)\n"; > } > } > $obj = new foo; > $obj->test(); > ?> > > This is different because we call into an object of type bar. Now in scope > bar we do not know anything about foo::test. <?php class foo { private $a = 'a'; public function test() { echo( $this->a ); } } class bar extends foo { private $a = 'b'; public function test2() { echo( $this->a ); } } $obj = new bar; $obj->test(); $obj->test2(); ?> Now i understood what u mean by 'bar' scope... :S I'm in need of a good scope article, some one know a good one? That said we should probably > allow __call there rather than the error. And it is easy enought o fix as > we know that in bar we have only inherited foo::test. > > If we move __call into foo it is the other way around then again. This is > because we will call into the object and start method resolution at scope > bar. As that does not know anything about test, we will use the inherited > method call to dynamically handle the call. However, that means we are in > scope foo where we do know about test and hence should issue the error. > But we will have a harder time issuing that error. As inside the engine we > actually never go down to scope foo and instead simply use the inherited > __call. > > So yes, this can be seen as a bug and part of it can easily be fixed. But > I do not see an easy way to fix it 100% according to inheritance rules. > > Best regards, > Marcus > -- Thanks for your attention, Diogo Neves Web Developer @ SAPO.pt by PrimeIT.pt -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php