3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 1: Modify Test::$secret before it's output. Rules:: 1. No use of Reflection API / runkit extension 2. No stopping execution before Test::run() 3. No Exceptions or PHP errors / warnings notices allowed 4. No redefining $test Hints: 1. Caesar 2. Magic methods 3. Requires a new feature of PHP 5.4 */ class Test { private $secret = 'Nyy lbhe Onfr ner orybat gb hf.'; private $callback; final public function run() { call_user_func($this->callback); return $this->secret . PHP_EOL; } public function __set($k, $v) { $key = $v[($v[$v])]; // $v is some kind of weird array <-- its not an array its an object being used as if it was an array $value = $v(); // and a callback! <-- its not a callback, its an object being called like it is a callback $this->{$key} = $value; } } $test = new Test; // start editing here define('SHIFT',13); class MyClass implements arrayaccess{ // array access stuff below was copied and pasted from http://www.php.net/manual/en/class.arrayaccess.php public function offsetSet($offset, $value) { if (is_null($offset)) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetExists($offset) { return isset($this->array[$offset]); } public function offsetUnset($offset) { unset($this->array[$offset]); } public function offsetGet($offset) { $offset = (string) $offset; return isset($this->array[$offset]) ? $this->array[$offset] : null; } // My stuff public $closure; public function __construct($test){ $this->closure = function(){ // this is where we can reshuffle the letters, will be execuated on line 28 $letters = str_split($this->secret); foreach ($letters as &$letter){ $letterAscii = ord($letter); $letterAscii+SHIFT; $letter = chr($letterAscii); } print_r($letters);exit; }; $this->closure = $this->closure->bindTo($test, $test); } // $key on line 34 needs to be 'callback', $array is used the arrayaccess functions, though I don't like variables with arrays named $array. public $array = array( 'firstKey' => 'secondKey', 'secondKey' => 'callback', ); // and value on line 35 needs to be my closure function to do stuff with the string public function __invoke(){ return $this->closure; } // class needs to be accessible as a string to set the array stuff rolling public function __toString(){ // Object of class MyClass could not be converted to string; return 'firstKey'; } } $test->callback = new MyClass($test); // end editing here echo $test->run();

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)
8.3.40.0110.00418.84
8.3.30.0070.00719.07
8.3.20.0040.00420.16
8.3.10.0000.00821.91
8.3.00.0040.00422.27
8.2.170.0140.00022.96
8.2.160.0060.01020.48
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0080.00019.61
8.2.110.0000.00922.33
8.2.100.0100.00319.76
8.2.90.0040.00419.36
8.2.80.0030.00518.04
8.2.70.0040.00417.63
8.2.60.0040.00418.16
8.2.50.0050.00318.07
8.2.40.0040.00418.16
8.2.30.0030.00618.17
8.2.20.0000.00817.77
8.2.10.0000.00819.64
8.2.00.0000.00817.92
8.1.270.0080.00022.14
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0040.00423.92
8.1.230.0100.00019.16
8.1.220.0030.00517.78
8.1.210.0050.00318.77
8.1.200.0030.00717.48
8.1.190.0000.00817.53
8.1.180.0030.00618.10
8.1.170.0000.00918.64
8.1.160.0050.00222.04
8.1.150.0040.00418.68
8.1.140.0070.00017.49
8.1.130.0030.00317.91
8.1.120.0040.00417.47
8.1.110.0040.00417.52
8.1.100.0000.00717.41
8.1.90.0040.00417.40
8.1.80.0030.00317.34
8.1.70.0040.00417.52
8.1.60.0050.00517.63
8.1.50.0000.00817.46
8.1.40.0040.00417.47
8.1.30.0040.00417.70
8.1.20.0030.00517.74
8.1.10.0050.00217.61
8.1.00.0040.00417.63
8.0.300.0050.00318.77
8.0.290.0040.00417.17
8.0.280.0000.00818.51
8.0.270.0000.00717.24
8.0.260.0030.00316.89
8.0.250.0000.00817.07
8.0.240.0050.00516.98
8.0.230.0080.00017.05
8.0.220.0080.00017.01
8.0.210.0030.00417.04
8.0.200.0030.00317.11
8.0.190.0000.00717.05
8.0.180.0040.00417.04
8.0.170.0040.00417.08
8.0.160.0040.00416.93
8.0.150.0040.00317.03
8.0.140.0040.00416.88
8.0.130.0000.00513.37
8.0.120.0040.00416.84
8.0.110.0000.00716.91
8.0.100.0040.00416.95
8.0.90.0070.00016.91
8.0.80.0110.00717.04
8.0.70.0030.00516.90
8.0.60.0040.00416.90
8.0.50.0040.00416.83
8.0.30.0080.01117.10
8.0.20.0050.01717.40
8.0.10.0040.00417.02
8.0.00.0100.01216.81
7.4.330.0060.00015.00
7.4.320.0000.00716.58
7.4.300.0080.00016.68
7.4.290.0070.00016.66
7.4.280.0060.00316.45
7.4.270.0030.00316.56
7.4.260.0070.00016.66
7.4.250.0050.00316.46
7.4.240.0030.00316.45
7.4.230.0040.00416.65
7.4.220.0140.00316.68
7.4.210.0070.01016.67
7.4.200.0040.00416.39
7.4.190.0000.00716.73
7.4.160.0110.00516.41
7.4.150.0090.00917.40
7.4.140.0110.00817.86
7.4.130.0100.00816.57
7.4.120.0050.01516.66
7.4.110.0140.00316.70
7.4.100.0040.01516.66
7.4.90.0060.01216.59
7.4.80.0110.00519.39
7.4.70.0030.01716.64
7.4.60.0130.00716.80
7.4.50.0060.00316.57
7.4.40.0100.00722.77
7.4.30.0030.01416.69
7.4.00.0000.01314.89
7.3.330.0030.00213.29
7.3.320.0050.00013.27
7.3.310.0040.00416.26
7.3.300.0000.00716.49
7.3.290.0100.00716.39
7.3.280.0070.01116.47
7.3.270.0090.00917.40
7.3.260.0060.01016.55
7.3.250.0130.00616.44
7.3.240.0090.00916.64
7.3.230.0100.01016.59
7.3.210.0100.01216.46
7.3.200.0170.00519.39
7.3.190.0030.01416.56
7.3.180.0100.00716.49
7.3.170.0080.01016.52
7.3.160.0050.01116.46
7.3.120.0000.01514.96
7.2.330.0100.00516.74
7.2.320.0130.01016.80
7.2.310.0060.01216.81
7.2.300.0090.01416.84
7.2.290.0060.00916.64
7.2.00.0070.00718.98
7.1.200.0090.00315.84
7.1.100.0000.01218.24
7.1.70.0000.00817.21
7.1.60.0100.01419.82
7.1.50.0070.00716.91
7.1.00.0030.07722.37
7.0.200.0100.00316.63
7.0.140.0030.07321.98
7.0.60.0170.07719.99
7.0.50.0130.07317.88
7.0.40.0000.06720.11
7.0.30.0370.07720.24
7.0.20.0230.06720.24
7.0.10.0270.08020.07
7.0.00.0130.07720.18
5.6.280.0100.07021.09
5.6.210.0070.07320.52
5.6.200.0000.04318.14
5.6.190.0030.04320.48
5.6.180.4130.04020.48
5.6.170.0270.08020.46
5.6.160.0130.07020.50
5.6.150.0070.07718.24
5.6.140.0070.08318.27
5.6.130.0100.04718.24
5.6.120.0100.07721.00
5.6.110.0000.07721.00
5.6.100.0100.08020.98
5.6.90.0170.07321.00
5.6.80.0100.07020.56
5.6.70.0400.06720.37
5.5.350.0030.08020.45
5.5.340.0070.03717.96
5.5.330.0130.07320.41
5.5.320.0170.08020.27
5.5.310.0330.06720.32
5.5.300.0030.07018.08
5.5.290.0030.08317.98
5.5.280.0000.04320.89
5.5.270.0000.04320.78
5.5.260.0100.08720.80
5.5.250.0130.03320.60
5.5.240.0100.04320.29
5.4.450.0670.05319.71
5.4.440.0670.06019.61
5.4.430.0130.05319.36
5.4.420.0170.05019.46
5.4.410.0070.05719.21
5.4.400.0830.00018.82
5.4.390.0900.00018.71
5.4.380.0270.05318.58
5.4.370.0100.05718.71
5.4.360.0070.05718.75
5.4.350.0270.04718.53
5.4.340.0130.05318.58
5.4.320.0060.04612.52
5.4.310.0060.03912.52
5.4.300.0070.04212.52
5.4.290.0070.04512.52
5.4.280.0050.04712.41
5.4.270.0030.06318.84
5.4.260.0100.07318.76
5.4.250.0170.06318.94
5.4.240.0100.08318.76
5.4.230.0130.05319.04
5.4.220.0130.07319.00
5.4.210.0130.05318.79
5.4.200.0100.08018.65
5.4.190.0070.08318.94
5.4.180.0130.05318.79
5.4.170.0200.05318.99
5.4.160.0070.06319.00
5.4.150.0070.05318.77
5.4.140.0070.07716.36
5.4.130.0030.05016.43
5.4.120.0200.06016.64
5.4.110.0100.07016.54
5.4.100.0070.06016.41
5.4.90.0100.05716.48
5.4.80.0170.06716.59
5.4.70.0100.05016.52
5.4.60.0000.07016.56
5.4.50.0100.06016.31
5.4.40.0400.04716.52
5.4.30.0130.06316.47
5.4.20.0200.04316.59
5.4.10.0130.06716.59
5.4.00.0200.04715.80
5.3.290.0110.03712.80
5.3.280.0070.06014.79
5.3.270.0100.04714.72
5.3.260.0070.07014.54
5.3.250.0070.06314.80
5.3.240.0030.05714.71
5.3.230.0100.06014.79
5.3.220.0000.06714.68
5.3.210.0130.04714.66
5.3.200.0170.06014.77
5.3.190.0030.06314.58
5.3.180.0070.06014.50
5.3.170.0000.06014.81
5.3.160.0130.06714.61
5.3.150.0200.05314.68
5.3.140.0230.05314.59
5.3.130.0030.05714.66
5.3.120.0170.05314.67
5.3.110.0100.06014.65
5.3.100.0100.07014.09
5.3.90.0130.05314.13
5.3.80.0100.05714.20
5.3.70.0030.06314.20
5.3.60.0170.06014.10
5.3.50.0130.06013.88
5.3.40.0100.05013.96
5.3.30.0130.05313.92
5.3.20.0030.05713.82
5.3.10.0030.05713.85
5.3.00.0000.05713.63
5.2.170.0030.05011.23
5.2.160.0030.05311.07
5.2.150.0130.04711.15
5.2.140.0130.03711.34
5.2.130.0000.04711.13
5.2.120.0030.04011.02
5.2.110.0130.04711.21
5.2.100.0100.05711.11
5.2.90.0070.04011.34
5.2.80.0070.05711.29
5.2.70.0130.05011.19
5.2.60.0030.04711.29
5.2.50.0030.06311.04
5.2.40.0100.05010.86
5.2.30.0070.04311.18
5.2.20.0130.04011.06
5.2.10.0130.04011.10
5.2.00.0100.06010.91
5.1.60.0100.0479.97
5.1.50.0000.0409.98
5.1.40.0100.03010.24
5.1.30.0070.04310.35
5.1.20.0030.04010.54
5.1.10.0130.04010.14
5.1.00.0100.04010.07
5.0.50.0000.0408.80
5.0.40.0170.0278.53
5.0.30.0070.0478.33
5.0.20.0070.0338.15
5.0.10.0070.0278.25
5.0.00.0100.0408.10
4.4.90.0030.0206.20
4.4.80.0070.0236.20
4.4.70.0030.0336.20
4.4.60.0030.0206.20
4.4.50.0100.0276.20
4.4.40.0070.0376.20
4.4.30.0030.0306.20
4.4.20.0030.0206.20
4.4.10.0030.0276.20
4.4.00.0000.0376.20
4.3.110.0130.0236.20
4.3.100.0030.0236.20
4.3.90.0030.0236.20
4.3.80.0100.0336.20
4.3.70.0000.0236.20
4.3.60.0000.0336.20
4.3.50.0030.0206.20
4.3.40.0000.0436.20
4.3.30.0070.0236.20
4.3.20.0070.0176.20
4.3.10.0030.0236.20
4.3.00.0100.0206.55

preferences:
29.93 ms | 400 KiB | 5 Q