<?php
interface BarInterface {
/**
* Bazzes the current environment.
*/
public function baz();
}
class Foo implements FooInterface {
/**
* @var \BarInterface
*/
protected $bar;
/**
* Constructs a new instance.
*
* @param \BarInterface $bar
*/
public function __construct(BarInterface $bar) {
$this->bar = $bar;
}
/**
* Bazzes the bar.
*/
public function baz() {
$this->bar->baz();
}
}
class NullBar implements BarInterface {
/**
* {@inheritdoc}
*/
public function baz() {
// Silently fail.
}
}
class ShoutBar implements BarInterface {
/**
* {@inheritdoc}
*/
public function baz() {
print "HELLO BAZ!";
}
}
$null_bar = new NullBar();
$shout_bar = new ShoutBar();
$null_bar_foo = new Foo($null_bar);
$null_bar_foo->baz();
$shout_bar_foo = new Foo($shout_bar);
$shout_bar_foo->baz();
Fatal error: Uncaught Error: Interface "FooInterface" not found in /in/1ohuo:11
Stack trace:
#0 {main}
thrown in /in/1ohuo on line 11
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Interface 'FooInterface' not found in /in/1ohuo:11
Stack trace:
#0 {main}
thrown in /in/1ohuo on line 11
Process exited with code 255.