There is nothing that would allow you to do
class Foo extendsIfExist Bar
But you can monkeypatch foo with runkit
An example from the PHP manual:
class myParent {
function parentFunc() {
echo "Parent Function Output\n";
}
}
class myChild {
}
runkit_class_adopt('myChild','myParent');
myChild::parentFunc();
The runkit extension is available in PECL. However, using this is not recommended , because it is almost always an indicator for erroneous design.
: , - - , . , .
, , , . -
interface Loggable
{
public function log($message);
}
class Foo implements Loggable
{
protected $logger;
public function setLogger($logger)
{
$this->logger = $logger;
}
public function log($message)
{
if($this->logger !== NULL) {
return $this->logger->log($message);
}
}
}
log(). , , , Foo, , , Loggable. Logger, Foo. , , . solid.