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 interface Answer implements AnswerInterface { public function __toString() { return "4"; } public function get() { return $this; } public function the() { return $this; } public function answer() { return $this; } } // 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)
7.0.60.1000.01014.07
7.0.50.1170.01314.29
7.0.40.1470.01014.32
7.0.30.1070.01014.29
7.0.20.1300.00714.10
7.0.10.1830.01014.22
7.0.00.1970.01714.36
5.6.210.0100.05720.79
5.6.200.0170.05720.56
5.6.190.0170.06020.60
5.6.180.0070.06020.75
5.6.170.0200.06720.59
5.6.160.0330.07020.77
5.6.150.0100.06020.60
5.6.140.0030.07020.75
5.6.130.0130.08320.60
5.6.120.0030.08320.64
5.6.110.0170.05320.59
5.6.100.0270.06320.58
5.6.90.0130.05320.66
5.6.80.0130.05019.97
5.5.350.0100.08017.34
5.5.340.0200.06318.09
5.5.330.0170.07317.89
5.5.320.0030.06317.87
5.5.310.0200.06717.87
5.5.300.0100.06017.85
5.5.290.0230.05317.88
5.5.280.0200.07017.64
5.5.270.0070.07017.83
5.5.260.0130.05717.87
5.5.250.0030.07017.65
5.5.240.0100.05317.02
5.4.450.0100.05719.30
5.4.440.0200.05019.13
5.4.430.0100.05319.29
5.4.420.0070.06019.25
5.4.410.0030.05719.15
5.4.400.0130.05319.11
5.4.390.0130.05018.84
5.4.380.0100.05718.80
5.4.370.0130.06018.98
5.4.360.0130.05318.83
5.4.350.0100.07719.11
5.4.340.0130.06719.00
5.4.320.0030.06318.96
5.4.310.0100.05019.10
5.4.300.0270.03718.80
5.4.290.0070.06018.91
5.4.280.0030.06018.80
5.4.270.0050.04515.56
5.4.260.0070.04515.66
5.4.250.0110.04515.74
5.4.240.0100.04515.54
5.4.230.0050.06215.67
5.4.220.0110.04615.67
5.4.210.0060.05715.68
5.4.200.0110.05315.74
5.4.190.0090.05715.70
5.4.180.0080.04515.57
5.4.170.0160.04415.69
5.4.160.0050.05015.65
5.4.150.0060.06315.69
5.4.140.0080.05114.29
5.4.130.0080.04914.26
5.4.120.0050.04914.20
5.4.110.0060.04514.28
5.4.100.0050.05014.24
5.4.90.0060.04714.29
5.4.80.0040.04414.33
5.4.70.0080.03914.33
5.4.60.0070.04214.32
5.4.50.0080.04214.26
5.4.40.0060.04814.25
5.4.30.0070.05014.22
5.4.20.0060.04314.25
5.4.10.0080.04514.18
5.4.00.0080.04413.77
5.3.290.0070.05714.75
5.3.280.0110.04113.70
5.3.270.0030.05013.76
5.3.260.0030.05113.66
5.3.250.0030.05213.70
5.3.240.0060.04613.75
5.3.230.0040.04713.70
5.3.220.0070.04513.54
5.3.210.0110.04213.67
5.3.200.0070.04813.67
5.3.190.0050.05813.62
5.3.180.0100.05313.66
5.3.170.0060.04613.57
5.3.160.0080.04413.62
5.3.150.0090.04613.63
5.3.140.0070.04313.72
5.3.130.0120.04413.64
5.3.120.0030.05313.66
5.3.110.0060.04613.61
5.3.100.0100.04013.17
5.3.90.0060.04913.09
5.3.80.0070.05113.06
5.3.70.0120.04813.05
5.3.60.0060.04413.15
5.3.50.0080.04513.07
5.3.40.0060.04712.98
5.3.30.0060.04712.99
5.3.20.0160.04712.76
5.3.10.0100.05412.69
5.3.00.0080.05012.75

preferences:
144.28 ms | 1386 KiB | 7 Q