php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42370 Inheritance problem
Submitted: 2007-08-22 08:36 UTC Modified: 2007-08-22 08:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: chauhansudhir at fastmail dot in Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.3 OS: Win XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chauhansudhir at fastmail dot in
New email:
PHP Version: OS:

 

 [2007-08-22 08:36 UTC] chauhansudhir at fastmail dot in
Description:
------------
When we inherit classes and creates an object of derieved class the constructor of parent classes are not executed we need to execute this explicitly. Please check the following code

Reproduce code:
---------------
<?php
abstract class a {
	function __construct() {		
		print "a";
	}
}

class b extends a {
	function __construct() {
		print "b";
	}
}

class  c extends b {
	function __construct() {
		print "c";
	}
}

$v = new c();

?>

Expected result:
----------------
abc but it ab getting on c why so? as inheritance moves form parent to child same as java.

Actual result:
--------------
c

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-22 08:44 UTC] derick@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

This is how php works, you have to call parent::__construct() yourself.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 06:01:30 2025 UTC