Battle Of Definition¶
<?php
interface I {
function __construct(int $i);
}
class X implements I {
function __construct(int $i) {}
}
// Fatal error: Declaration of Yy::__construct(string $a) must be
// compatible with I::__construct(int $i)
class Y extends X {
function __construct(string $a) {}
}
?>
Methods signatures must be compatible with the parent class’s definition. This is true, except for __construct(), for which the compatibility is never checked.
Yet, compatibility is still enforced when the __construct() definition is in an interface. Then, both the implementing table and all its children must have the interface’s compatibility.
See Also¶
PHP Features¶
Last updated: 14 July 2026