In modern versions of PHP (5.6 below), the following is an invalid program
error_reporting(E_ALL);
class A
{
public function hello(X $one, Y $two)
{
}
}
class B extends A
{
public function hello()
{
}
}
interface X
{
}
interface Y
{
}
$b = new B;
PHP will refuse to run this, and instead give you an error message like the following
PHP Strict standards: Declaration of B::hello() should be compatible with A::hello(X $one, Y $two) in test.php on line 15
Strict standards: Declaration of B::hello() should be compatible with A::hello(X $one, Y $two) in test.php on line 15
This is a Good Thing™ from a strictness point of view. However, if you try the same thing with a constructor function
class A
{
public function __construct(X $one, Y $two)
{
}
}
class B extends A
{
public function __construct()
{
}
}
PHP has no problem, and will run the program.
Does anyone know the history and/or technical context of why strict standard don't apply to constructors?