php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66894 Taking old-style-constructor instead of unified one
Submitted: 2014-03-12 22:59 UTC Modified: 2017-01-08 16:27 UTC
From: nicolas dot abbuehl at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Class/Object related
PHP Version: Irrelevant OS:
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: nicolas dot abbuehl at gmail dot com
New email:
PHP Version: OS:

 

 [2014-03-12 22:59 UTC] 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'.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-13 01:35 UTC] rasmus@php.net
-Status: Open +Status: Analyzed
 [2014-03-13 01:35 UTC] 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-13 01:35 UTC] rasmus@php.net
-Type: Bug +Type: Documentation Problem
 [2014-03-13 05:51 UTC] 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.
 [2017-01-08 16:25 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=341633
Log: Fix #66894: Taking old-style-constructor instead of unified one
 [2017-01-08 16:27 UTC] cmb@php.net
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: cmb
 [2017-01-08 16:27 UTC] cmb@php.net
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.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=38d634a6b5e3ac34076fe9053a0d1fc042772aa3
Log: Fix #66894: Taking old-style-constructor instead of unified one
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 10:01:28 2024 UTC