<?php
interface GoAlgorithm
{
public function go();
}
class GoByDrivingAlgorithm implements GoAlgorithm
{
public function go()
{
echo("Now I'm driving.");
}
}
class GoByFlying implements GoAlgorithm
{
public function go()
{
echo("Now I'm flying.");
}
}
class GoByFlyingFast implements GoAlgorithm
{
public function go()
{
echo("Now I'm flying fast");
}
}
class Vehicle
{
private $goAlgorithm;
public function setModeOfTransportation(GoAlgorithm $goType)
{
$this->goAlgorithm = $goType;
}
public function drive()
{
return $this->goAlgorithm->go();
}
}
$streetRacer = new Vehicle();
$formulaone = new Vehicle();
$helicopter = new Vehicle();
$jets = new Vehicle();
$streetRacer->drive();
$formulaone->drive();
$helicopter->drive();
$jets->drive();
Fatal error: Uncaught Error: Call to a member function go() on null in /in/O8Y1I:45
Stack trace:
#0 /in/O8Y1I(54): Vehicle->drive()
#1 {main}
thrown in /in/O8Y1I on line 45
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Fatal error: Call to a member function go() on null in /in/O8Y1I on line 45
Process exited with code 255.