php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50870 Constructor parameters do not have to match those of superclass constructor
Submitted: 2010-01-28 07:59 UTC Modified: 2010-02-24 12:44 UTC
From: sjoerd-php at linuxonly dot nl Assigned: degeberg (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2010-01-28 07:59 UTC] sjoerd-php at linuxonly dot nl
Description:
------------
It is unclear when a overloading method should have the same parameters as its superclass, this could use some documentation.

If you override a method in a subclass, the method needs to have the same parameters as the superclass. The following will trigger an E_STRICT:

class A {
	public function foo(stdClass $a) { }
}

class B extends A {
	public function foo($a) { }
}

Strict standards: Declaration of B::foo() should be compatible with that of A::foo()

This does not apply to the constructor. The __construct special method may have different parameters. The following will not give a notice:

class A {
	public function A(stdClass $a) { }
}

class B extends A {
	public function B($a) { }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-23 15:25 UTC] johannes@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

This is a design decision.
 [2010-02-23 15:34 UTC] johannes@php.net
Can't find it in the documentation, I thought I saw it there before :-/

So it was decided that we won't enforce the signature for constructors while we allow interfaces like

interface FixedCtor {
    function __construct(A $foo);
}

which enforces a compatible constructor, but default behavior is to be less strict with constructors.

The interface thing was added lateron.
 [2010-02-24 12:44 UTC] svn@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=295468
Log: Fixed PHP bug #50870 (Constructor parameters do not have to match those of superclass constructor)
 [2010-02-24 12:44 UTC] degeberg@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.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 23:00:01 2026 UTC