ДК
Size: a a a
ДК
a
a
abstract class Test
{
private $name;
public function __construct($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
abstract public function kill(Test $test);
}
class One extends Test
{
public function kill(Test $test)
{
return 'I\'m, ' . $this->getName() . ' kill ' . $test->getName() . '!';
}
}
$one1 = new One('One1');
$one2 = new One('One2');
echo $one2->kill($one1); //I'm, One2 kill One1!
echo $one2->kill($one2); //Exception
a
ДК
a
ДК
R
ДК
a
a
S
S
a
a
class One extends Test
{
public function kill(Test $test)
{
if (???) {
throw new \Exception('Нельзя убить самого себя');
}
return 'I\'m, ' . $this->getName() . ' kill ' . $test->getName() . '!';
}
}
S
ДК
class One extends Test
{
public function kill(Test $test)
{
if (???) {
throw new \Exception('Нельзя убить самого себя');
}
return 'I\'m, ' . $this->getName() . ' kill ' . $test->getName() . '!';
}
}
a
a
a