Hi Stanislav.

Thank you for replying. I agree that PHP can be different from other
languages, but i think you agree that a code like this just feels wrong:

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


One would never guess that $this inside a method of Duck could be an
instance of Cube. It might look silly as an example. But in the real world
someone could think a method is static when its not, and call it,
introducing a bug on the application.

I don't see any case where this behavior is useful. And even it there was
one, it could be achieved using magic methods __call() and __callStatic().


Thank you all,

*Carlos Rodrigues*
car...@jp7.com.br

2014-11-28 20:59 GMT-02:00 Stanislav Malyshev <smalys...@gmail.com>:

> Hi!
>
> > It confuses programmers that came from other languages, prevent APIs from
> > having meaningful names on static methods and have no other benefit than
> > supporting PHP 4 code.
>
> I think this notion of "confuses programmers" sometimes goes too far,
> and this is one of the examples. PHP prides itself about having low
> barrier to entry, but that doesn't mean you can refuse to learn anything
> at all about it and PHP should change to match that.
>
> There's nothing wrong in having static and non-static functions in the
> same namespace, and many languages do the same. Some do not, so you
> should just remember PHP is the one which does.
> --
> Stas Malyshev
> smalys...@gmail.com
>

Reply via email to