|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-05 19:53 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 12:00:01 2025 UTC |
Description: ------------ I want to extend a class C from another class class B who was extend from my abstract class A. I want to get the different value of the same variable. So I initialize my variable "name" and read the variable at my function "__toString()", so please look to my code couse my english is not the best ;) . its hard for me to explain. Reproduce code: --------------- abstract class A { public $name = "CLASS:A"; public function __toString(){ return " => ABSTRACT " . $this->name; } } class B extends A { public function __construct(){ $this->name = "CLASS:B"; } public function __toString(){ return " => " . $this->name . parent::__toString(); } } class C extends B { public function __construct(){ parent::__construct(); $this->name = "CLASS:C"; } } $deb_b = new B(); $deb_c = new C(); printf("Result: Beginn B %s<br />", $deb_b); printf("Result: Beginn C %s<br />", $deb_c); Expected result: ---------------- Result: Beginn B = => CLASS:B => ABSTRACT CLASS:B Result: Beginn C = => CLASS:C => ABSTRACT CLASS:C Actual result: -------------- Result: Beginn B => CLASS:B => ABSTRACT CLASS:A Result: Beginn C => CLASS:C => CLASS:B => ABSTRACT CLASS:A