Doc #66894 [Ana->Csd]: Taking old-style-constructor instead of unified one
| From: | cmb@php.net | Date: | Sun, 08 Jan 2017 16:27:30 +0000 |
| Subject: | Doc #66894 [Ana->Csd]: Taking old-style-constructor instead of unified one | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14312@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
Updated by: cmb@php.net
Reported by: nicolas dot abbuehl at gmail dot com
Summary: Taking old-style-constructor instead of unified one
-Status: Analyzed
+Status: Closed
Type: Documentation Problem
Package: Class/Object related
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2017-01-08 16:25:07] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=341633
Log: Fix #66894: Taking old-style-constructor instead of unified one
------------------------------------------------------------------------
[2014-03-13 05:51:15] nicolas dot abbuehl at gmail dot com
Yes, I meant to have ChildClass extend ParentClass, I failed to copy out my code the correct way.
Sorry about that.
------------------------------------------------------------------------
[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