RE: [PHP] context when calling non static method of class in a static way
| From: | admin at buskirkgraphics dot com | Date: | Sun, 22 May 2011 14:42:29 +0000 |
| Subject: | RE: [PHP] context when calling non static method of class in a static way | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313076@lists.php.net to get a copy of this message | ||
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php