<?php
interface testInterface
{
public function doAction();
}
class Foo implements testInterface
{
public function doAction()
{
echo "Action!";
}
}
class Bar
{
protected $test = "test";
}
class Baz
{
public function __construct(testInterface $class)
{
echo "Everything's ok!";
}
}
$foo = new Foo();
$bar = new Bar();
$baz = new Baz($bar);
Fatal error: Uncaught TypeError: Baz::__construct(): Argument #1 ($class) must be of type testInterface, Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD:23
Stack trace:
#0 /in/vilbD(31): Baz->__construct(Object(Bar))
#1 {main}
thrown in /in/vilbD on line 23
Process exited with code 255.
Fatal error: Uncaught TypeError: Argument 1 passed to Baz::__construct() must implement interface testInterface, instance of Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD:23
Stack trace:
#0 /in/vilbD(31): Baz->__construct(Object(Bar))
#1 {main}
thrown in /in/vilbD on line 23
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Catchable fatal error: Argument 1 passed to Baz::__construct() must implement interface testInterface, instance of Bar given, called in /in/vilbD on line 31 and defined in /in/vilbD on line 23
Process exited with code 255.