|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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) { }
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 23:00:01 2026 UTC |
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.