Class Implement No More¶
<?php
try {
$x = initSomething();
doSomething(); // may throw an exception
}
// no catch: exception keep their way
// finally is always executed
// with or without exception being caught
finally{
$x->shutdown();
}
?>
Inheritance forces children classes to have only methods that are compatible with the parent’s methods.
The only exception is the constructor, which may have a totally different signature from generation to generation.
Interfaces apply the same constraints: their methods signature must be compatible with the host class. In this case, it also applies to the constructor.
So, in the case a parent class implements an interface with a constructor, and this class has a child class, the child may look compatible with the interface, and yet, be invalid at the constructor level.
Another good reason to avoid placing constructors in interfaces.
See Also¶
PHP Features¶
Last updated: 14 July 2026