3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Base { protected $foo = null; final public function __construct(Granny $init = null) { return $this->init($init); } //protected function init(Granny $dependency = null) //{} } interface IObject { protected function init(Granny $dependency = null); } class Granny { protected $name = null; protected $age = null; public function __construct(array $vals = null) { foreach($vals as $name => $val) { $name = 'set'.ucfirst($name); if (method_exists($this, $name)) { $this->{$name}($val); } } return $this; } //basic gettter && setters public function getAge() { return $this->age; } public function setAge($age = null) { $this->age = $age === null ? null : (int) $age; return $this; } } class Dad extends Granny { //Dad's secret private $likesMom = null; public function getLikesMom() { return $this->likesMom; } public function setLikesMom($bool = null) { $this->likesMom = $bool === null ? null : !!$bool; return $this; } } class Ball extends Base implements IObject { protected function init(Dad $dependency = null) { $this->foo = $dependency; return $this; } } var_dump(new Ball());
Output for 5.3.0 - 5.4.17
Fatal error: Access type for interface method IObject::init() must be omitted in /in/PSqvI on line 13
Process exited with code 255.