static call to an instance method in a class definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ?

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux