What is going on here in PHP with classes?

serpicosk

New Member
If I have this code, the string "test" is echoed. This is in PHP 5.3. Is this some oversight that shouldn't be relied on, or is it some way of achieving multiple inheritence in PHP?\[code\]class Test1{ function getName() { return $this->name; }}class Test2{ public $name = 'test'; function getName() { return Test1::getName(); }}$test = new Test2;echo $test->getName();\[/code\]EDIT:As has been pointed out the comments by GZipp this is actually documented behaviour. See this page: http://us2.php.net/manual/en/language.oop5.basic.php and the heading "Example #2 Some examples of the $this pseudo-variable".Classes A and B have a similar relationship to my two test classes above and the lines\[code\]$b = new B();$b->bar();\[/code\]Show more or less the same result as my example.
 
Back
Top