Re: Static functions Vs Nonstatic functions
| From: | Stanislav Malyshev | Date: | Mon, 01 Dec 2014 17:25:50 +0000 |
| Subject: | Re: Static functions Vs Nonstatic functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79350@lists.php.net to get a copy of this message | ||
Hi!
> class Cube {
> function weird() {
> echo Duck::foo();
> }
>
> }
>
> class Duck {
> public function foo() {
> echo 'My class is: ' . get_class($this);
> }
> }
>
> $rubik = new Cube;
> $rubik->weird(); // Output: My class is: Cube
This code produces:
Deprecated: Non-static method Duck::foo() should not be called
statically, assuming $this from incompatible context
which informs you about the fact that what you're doing is wrong. This
capability is kept for BC reasons. There was a discussion about dropping
this from PHP 7 but it wasn't yet decided to remove the support. In any
case, this has little to do with static and non-static functions having
different namespaces.
--
Stas Malyshev
smalyshev@gmail.com