3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 2: Implement AnswerInterface and get Question to echo "4". */ 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(); } // start editing here class Answer implements AnswerInterface { public function get() { return $this; } public function the() { return $this; } public function answer() { return $this; } public funcion __toString() { return '4'; } } $answer = new Answer(); // end editing here $answer = new Answer; $question = new Question($answer);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.4.250.0130.07318.90
5.4.240.0100.06019.01
5.4.230.0270.05318.95
5.4.220.0170.06718.99
5.4.210.0070.07718.95
5.4.200.0130.06718.95
5.4.190.0070.07718.95
5.4.180.0070.07719.01
5.4.170.0070.07019.04
5.4.160.0170.07018.89
5.4.150.0130.05718.98
5.4.140.0200.05016.46
5.4.130.0100.05016.43
5.4.120.0070.05316.60
5.4.110.0130.07316.43
5.4.100.0100.04716.47
5.4.90.0100.05016.46
5.4.80.0100.05016.38
5.4.70.0200.05716.45
5.4.60.0070.05016.37
5.4.50.0070.05716.52
5.4.40.0100.04716.52
5.4.30.0000.06716.38
5.4.20.0030.05716.39
5.4.10.0070.05316.52
5.4.00.0070.05715.98
5.3.280.0100.05314.60
5.3.270.0170.04714.84
5.3.260.0200.05714.61
5.3.250.0170.06014.70
5.3.240.0030.07314.45
5.3.230.0100.07014.68
5.3.220.0100.07314.66
5.3.210.0070.06314.67
5.3.200.0130.05714.75
5.3.190.0070.07314.60
5.3.180.0100.06714.80
5.3.170.0200.04014.59
5.3.160.0030.05314.65
5.3.150.0100.05314.56
5.3.140.0070.06714.55
5.3.130.0100.06014.58
5.3.120.0130.06714.55
5.3.110.0130.04714.56
5.3.100.0230.05014.13
5.3.90.0200.06314.00
5.3.80.0070.07014.02
5.3.70.0130.04714.05
5.3.60.0030.07713.92
5.3.50.0070.05713.86
5.3.40.0030.06313.94
5.3.30.0170.04313.92
5.3.20.0130.05013.67
5.3.10.0100.04713.64
5.3.00.0100.05313.55

preferences:
137.8 ms | 1394 KiB | 7 Q