php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48807 Problem with extending classes
Submitted: 2009-07-05 16:40 UTC Modified: 2009-07-05 19:53 UTC
From: Denfie at gmx dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.10 OS: ubuntu4.1
Private report: No CVE-ID: None
 [2009-07-05 16:40 UTC] Denfie at gmx dot net
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-05 19:53 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC