Bug #66894 [Opn->Ana]: Taking old-style-constructor instead of unified one

From: Date: Thu, 13 Mar 2014 01:35:00 +0000
Subject: Bug #66894 [Opn->Ana]: Taking old-style-constructor instead of unified one
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184766@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: rasmus@php.net Reported by: nicolas dot abbuehl at gmail dot com Summary: Taking old-style-constructor instead of unified one -Status: Open +Status: Analyzed Type: Bug Package: Class/Object related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#184766) next »