<?php
class Foo {
protected $bar;
public function __construct(BarInterface $bar)
{
$this->bar = $bar;
}
public function doAction()
{
echo $this->bar->getVar();
}
}
interface BarInterface
{
public function getVar();
}
abstract class BarAbstract implements BarInterface
{
public function getVar()
{
return $this->var;
}
}
class Bar extends BarAbstract
{
protected $var = __CLASS__;
}
class Baz extends BarAbstract
{
protected $var = __CLASS__;
}
$bar = new Bar();
$foo = new Foo($bar);
$foo->doAction();