3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?PHP class Question { public function __construct(AnswerInterface $answer) { echo "What is 2 + 2?\n"; $answer = $answer->get()->the()->answer(); if ($answer instanceof AnswerInterface) { echo $answer . PHP_EOL; } } } interface AnswerInterface { public function get(); public function the(); public function answer(); } class Answer implements AnswerInterface{ private $answer; public function get(){ $this->answer = 2; return $this; } public function the(){ $this->answer = $this->answer + 2; return $this; } public function answer(){ return $this->answer; } } $answer = new Answer; $question = new Question($answer);
based on iklTX
Output for 7.0.0 - 7.2.6
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Answer has a deprecated constructor in /in/g9ekn on line 22 What is 2 + 2?
Output for 5.6.0 - 5.6.30, hhvm-3.15.4
What is 2 + 2?