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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 18:01:35 2024 UTC