Re: context when calling non static method of class in a static way

From: Date: Sun, 22 May 2011 20:52:06 +0000
Subject: Re: context when calling non static method of class in a static way
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-313082@lists.php.net to get a copy of this message
the good thing about this "bug" would be, that it's not neccesary to extend a class to use its methods as if they would be defined in the extending class. this way i think it would be possible to implement something like multiple inheritance, which is currently not (that easy) possible. when i'll find time i'll test how attributes behave that way. Am 22.05.2011 22:31, schrieb admin@buskirkgraphics.com:
Correct that. I do not know what I was even thinking when I wrote that response. It does not make any sense what so ever. The class is already extended of course I can call a method from it. Sorry Richard L. Buskirk -----Original Message----- From: Simon Hilz [mailto:simon.hilz@gmx.de] Sent: Sunday, May 22, 2011 11:56 AM To: php-general@lists.php.net Subject: Re: [PHP] context when calling non static method of class in a static way Richard, yes! at least my example works. i didn't test it any further; i doubt it is intended that way. Simon Hilz Am 22.05.2011 16:42, schrieb admin@buskirkgraphics.com:
Simon, So without extending foo you can run bar in another class? Richard L. Buskirk -----Original Message----- From: Simon Hilz [mailto:simon.hilz@gmx.de] Sent: Sunday, May 22, 2011 10:18 AM To: php-general@lists.php.net Subject: [PHP] context when calling non static method of class in a static way hi, lets assume the following classes: class Foo{ public function bar() { echo get_class($this); } } class Foobar{ public function callBarStatic() { Foo::bar(); } } the following code results in the output "Foobar": $obj = new Foobar(); $obj->callBarStatic(); That means that the static call of bar() is executed in the context of Foobar. Is this behavior deliberate? If so, it would open a great way of object composition patterns. But only if it will be retained in future versions :) (i've tested with 5.3.5) Simon Hilz


« previous php.general (#313082) next »