php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41428 Calling parent::__construct() causes a fatal error
Submitted: 2007-05-18 09:14 UTC Modified: 2007-05-18 10:58 UTC
From: dasher at inspiredthinking dot co dot uk Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.2 OS: Windows Vista Ultimate x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dasher at inspiredthinking dot co dot uk
New email:
PHP Version: OS:

 

 [2007-05-18 09:14 UTC] dasher at inspiredthinking dot co dot uk
Description:
------------
Calling parent::_construct() from an extended class causes a fatal error when the parent doesn't have a constructor.

When you've full control over the code - it's not an issue - but when the parent comes from a code library it's becomes difficult to know if you should call the constructor.  With code libraries such as PEAR - the parent class might not have a constructor today but might have one tomorrow.



Reproduce code:
---------------
class parentClass {
  function someMethod() {
  }
}

class childClass extends parentClass {
  function childClass() {
    parent::parentClass();
  }
}

$obj = new childClass();

Expected result:
----------------
The code above should run without generating a Fatal error - at most the error should be an E_NOTICE or E_WARNING.

Actual result:
--------------
Fatal error: Can not call constructor in filename.php on Line 007

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-18 09:24 UTC] judas dot iscariote at gmail dot com
huh ? it raises the expected error message..

PHP Fatal error:  Call to undefined method parentClass::parentclass()

this is the expected behaviuor as  parent::parentClass(); does not exists at all.
 [2007-05-18 10:58 UTC] sniper@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 10 19:01:34 2025 UTC