From: Ferenc Kovacs on
Hi.

I knew about this "feature" ($this is used from the caller scope if
the called method is static), but I didn't checked the manual about
this.
Now I did it.

http://php.net/manual/en/language.oop5.static.php
"Because static methods are callable without an instance of the object
created, the pseudo-variable $this is not available inside the method
declared as static."

some comments point out this behaviour, but either the code, or the
documentation is wrong.

Tyrael

On Thu, Jul 22, 2010 at 6:09 PM, samuel <zouliloua(a)gmail.com> wrote:
> Hello,
> Making a mistake I just come to discover ( for myself ) a strange fiture in
> php,
> lets see an example :
>
> class A{
>
>  public $foo = 'bar';
>
>  public function write(){
>
>   print($this->foo);
>
>  }
>
> }
>
>
> class B{
>
>  public $foo = 'gnagnagna';
>
>
>
>  public function write(){
>
>  A::write();
>
>  }
>
> }
>
>
> $var = new B;
>
> $var->write();
>
>
> This code will not throw excaption and output gnagnagna, it's kind of cross
> définition something,
> I know something like that exists in other language but I didn't expect PHP
> to work like that.
>
> Do you know this ? And why ?
>