Doc #66894 [Ana]: Taking old-style-constructor instead of unified one
| From: | nicolas dot abbuehl at gmail dot com | Date: | Thu, 13 Mar 2014 05:51:16 +0000 |
| Subject: | Doc #66894 [Ana]: Taking old-style-constructor instead of unified one | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11070@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66894&edit=1
ID: 66894
User updated by: nicolas dot abbuehl at gmail dot com
Reported by: nicolas dot abbuehl at gmail dot com
Summary: Taking old-style-constructor instead of unified one
Status: Analyzed
Type: Documentation Problem
Package: Class/Object related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Yes, I meant to have ChildClass extend ParentClass, I failed to copy out my code the correct way.
Sorry about that.
Previous Comments:
------------------------------------------------------------------------
[2014-03-13 01:35:00] rasmus@php.net
I assume you meant to have ChildClass extend ParentClass because as-written your example makes very
little sense.
This is however not a bug. If a class has an old-style constructor, it will be called, regardless of
whether its parent may have a constructor. So this is a documentation problem. Re-classifying.
And yes, it has always been like this for every version of PHP:
http://3v4l.org/hR9CM
------------------------------------------------------------------------
[2014-03-12 22:59:33] nicolas dot abbuehl at gmail dot com
Description:
------------
Following scenario:
A child-class, which is having an old-style-constructor (name of the child-class) extends a
parent-class with a unified constructor. When initializing a new child-class, the
child-class-constructor (which is the old one) get's carried out instead of the
unified-constructor of the parent-class. According to the documentation
(http://de.php.net/__construct, paragraph "For backwards compatibility, if PHP 5..."),
this is the wrong behaviour.
I am working with PHP 5.5.8, but it's reproducable in PHP 5.4 and 5.3.
Test script:
---------------
<?php
class ParentClass {
public function __construct() {
echo 'ParentClass';
}
}
class ChildClass {
public function ChildClass() {
echo 'ChildClass';
}
}
$obj = new ChildClass();
?>
Expected result:
----------------
The script should echo 'ParentClass'.
Actual result:
--------------
The script echoes 'ChildClass'.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66894&edit=1