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 <-- object needs to act like an array $value = $v(); // and a callback! <-- object needs to act like a callback $this->{$key} = $value; } } $test = new Test; // start editing here DEFINE('SHIFT', 13); class MyClass implements arrayaccess{ // array access code 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; } // end copied code public $closure; public function __construct($test) { $this->closure = function() { $letters = str_split($this->secret); $newLetters = array(); foreach ($letters as &$letter) { $ascii = ord($letter); $newAscii = $ascii; $pivot = (ctype_upper($letter) ? ord('A') : ord('a')) + SHIFT; if($letter != " "){ if ($ascii >= $pivot){ $newAscii = ($ascii - SHIFT); }else{ $newAscii = ($ascii + SHIFT); } } $letter = chr($newAscii); } $this->secret = join($letters); }; $this->closure = $this->closure->bindTo($test, $test); } // $array is used in the arrayaccess functions, ambigious name. public $array = array( 'firstKey' => 'secondKey', 'secondKey' => 'callback', ); public function __invoke(){ return $this->closure; } public function __toString(){ 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.60.0000.01518.40
8.3.50.0140.00522.05
8.3.40.0120.00318.80
8.3.30.0060.00919.23
8.3.20.0080.00020.34
8.3.10.0060.00321.92
8.3.00.0080.00022.40
8.2.180.0110.00716.88
8.2.170.0000.01822.96
8.2.160.0040.01120.52
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0050.00517.50
8.2.110.0000.01022.25
8.2.100.0100.00319.45
8.2.90.0080.00019.20
8.2.80.0030.00517.97
8.2.70.0000.00817.38
8.2.60.0050.00317.93
8.2.50.0060.00318.07
8.2.40.0040.00418.34
8.2.30.0060.00318.16
8.2.20.0040.00417.86
8.2.10.0000.00819.48
8.2.00.0040.00417.79
8.1.280.0100.01025.92
8.1.270.0000.00822.24
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0080.00023.96
8.1.230.0110.00018.89
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.25
8.1.190.0040.00417.41
8.1.180.0000.00818.10
8.1.170.0070.00318.59
8.1.160.0050.00322.05
8.1.150.0070.00018.60
8.1.140.0070.00017.50
8.1.130.0080.00017.87
8.1.120.0040.00417.39
8.1.110.0000.00817.38
8.1.100.0040.00417.34
8.1.90.0090.00017.49
8.1.80.0000.00717.48
8.1.70.0000.00717.49
8.1.60.0060.00317.46
8.1.50.0000.00717.58
8.1.40.0060.00317.55
8.1.30.0040.00417.69
8.1.20.0040.00417.68
8.1.10.0000.00817.50
8.1.00.0000.00717.55
8.0.300.0070.00018.77
8.0.290.0040.00417.17
8.0.280.0030.00318.47
8.0.270.0080.00017.29
8.0.260.0000.00716.91
8.0.250.0000.00716.91
8.0.240.0100.00016.96
8.0.230.0030.00316.93
8.0.220.0030.00316.99
8.0.210.0070.00016.92
8.0.200.0000.00616.96
8.0.190.0080.00016.99
8.0.180.0040.00416.95
8.0.170.0080.00016.89
8.0.160.0040.00416.82
8.0.150.0040.00416.91
8.0.140.0040.00416.79
8.0.130.0000.00613.33
8.0.120.0040.00416.91
8.0.110.0080.00016.94
8.0.100.0040.00416.72
8.0.90.0030.00516.97
8.0.80.0070.00716.92
8.0.70.0000.00816.82
8.0.60.0000.00816.75
8.0.50.0080.00016.95
8.0.30.0110.01217.13
8.0.20.0140.00617.44
8.0.10.0060.00316.88
8.0.00.0070.01416.88
7.4.330.0030.00315.12
7.4.320.0070.00016.70
7.4.300.0030.00316.70
7.4.290.0000.00716.57
7.4.280.0000.00716.55
7.4.270.0070.00016.57
7.4.260.0030.00316.66
7.4.250.0060.00316.55
7.4.240.0040.00416.50
7.4.230.0030.00316.39
7.4.220.0040.01516.57
7.4.210.0080.00816.59
7.4.200.0030.00316.53
7.4.190.0000.00716.78
7.4.160.0090.00616.42
7.4.150.0110.00817.40
7.4.140.0060.01217.86
7.4.130.0080.00916.57
7.4.120.0080.01016.55
7.4.110.0100.01016.39
7.4.100.0100.00716.50
7.4.90.0070.01116.50
7.4.80.0090.00919.39
7.4.70.0060.01516.78
7.4.60.0040.01416.47
7.4.50.0050.00016.30
7.4.40.0140.00022.77
7.4.30.0070.01016.61
7.4.00.0090.00615.04
7.3.330.0050.00013.41
7.3.320.0030.00313.39
7.3.310.0000.00816.26
7.3.300.0000.00716.39
7.3.290.0110.00316.30
7.3.280.0080.00916.39
7.3.270.0040.01317.40
7.3.260.0120.00616.61
7.3.250.0110.00716.46
7.3.240.0090.00916.57
7.3.230.0060.01316.68
7.3.210.0120.00316.60
7.3.200.0110.00719.39
7.3.190.0070.01016.54
7.3.180.0120.00316.32
7.3.170.0080.00816.45
7.3.160.0120.00616.37
7.3.120.0070.01014.88
7.2.330.0150.00916.83
7.2.320.0030.01416.84
7.2.310.0060.01016.62
7.2.300.0000.01816.80
7.2.290.0120.00916.45
7.2.00.0030.01219.43
7.1.100.0030.01018.23
7.1.70.0070.00017.10
7.1.60.0070.01719.82
7.1.50.0060.01717.09
7.1.00.0070.08722.41
7.0.200.0110.00316.80
7.0.140.0000.07721.95
7.0.60.0300.07319.87
7.0.50.0030.08317.93
7.0.40.0130.04320.14
7.0.30.0400.06720.34
7.0.20.0130.04320.09
7.0.10.0230.05020.12
7.0.00.0100.07720.29
5.6.280.0030.07321.14
5.6.210.0170.07020.69
5.6.200.0100.04318.17
5.6.190.0100.05320.52
5.6.180.0070.08320.56
5.6.170.0230.04720.55
5.6.160.0170.07320.56
5.6.150.0070.08718.29
5.6.140.0030.04018.21
5.6.130.0030.07318.28
5.6.120.0070.04021.04
5.6.110.0070.08020.92
5.6.100.0100.07321.03
5.6.90.0030.04321.04
5.6.80.0170.06320.43
5.5.350.0270.07020.36
5.5.340.0100.07018.02
5.5.330.0030.07320.19
5.5.320.0370.06720.38
5.5.310.0200.08320.39
5.5.300.0130.07318.05
5.5.290.0000.04317.98
5.5.280.0100.03720.78
5.5.270.0130.04720.89
5.5.260.0030.08720.86
5.5.250.0000.09720.71
5.5.240.0100.04720.30
5.4.450.0830.07019.62
5.4.440.0770.05719.16
5.4.430.0100.06019.64
5.4.420.0170.05019.36
5.4.410.0130.05718.75
5.4.400.0330.05318.86
5.4.390.0370.04718.58
5.4.380.0330.04718.49
5.4.370.0070.03718.59
5.4.360.0070.04318.53
5.4.350.0060.03312.04
5.4.340.0070.03512.03
5.4.320.0090.04012.53
5.4.310.0060.04512.52
5.4.300.0080.03412.53
5.4.290.0070.03512.51
5.4.280.0070.03912.41
5.4.270.0030.07318.80
5.4.260.0030.06318.84
5.4.250.0170.06719.02
5.4.240.0200.04718.76
5.4.230.0070.08318.96
5.4.220.0100.08019.02
5.4.210.0170.06018.94
5.4.200.0100.07018.80
5.4.190.0200.06319.00
5.4.180.0070.06018.93
5.4.170.0030.06718.98
5.4.160.0070.05318.94
5.4.150.0100.05718.64
5.4.140.0200.05316.59
5.4.130.0130.05016.44
5.4.120.0000.06016.48
5.4.110.0100.07016.48
5.4.100.0130.04716.47
5.4.90.0030.05316.68
5.4.80.0270.05316.52
5.4.70.0200.06316.44
5.4.60.0070.06316.54
5.4.50.0130.06716.49
5.4.40.0130.06716.42
5.4.30.0030.07016.45
5.4.20.0100.06016.45
5.4.10.0100.06716.39
5.4.00.0230.04715.94
5.3.290.0110.04212.80
5.3.280.0170.06714.67
5.3.270.0130.05714.71
5.3.260.0130.05014.64
5.3.250.0130.06314.73
5.3.240.0130.04714.86
5.3.230.0030.05714.64
5.3.220.0130.04314.57
5.3.210.0100.05014.67
5.3.200.0100.07014.61
5.3.190.0130.05314.43
5.3.180.0070.05314.69
5.3.170.0100.05314.50
5.3.160.0070.07014.50
5.3.150.0200.05714.51
5.3.140.0170.04714.69
5.3.130.0070.06014.74
5.3.120.0200.04714.57
5.3.110.0100.05014.66
5.3.100.0100.06714.15
5.3.90.0100.07014.04
5.3.80.0130.06314.05
5.3.70.0100.07714.03
5.3.60.0070.07013.86
5.3.50.0230.04714.14
5.3.40.0070.05014.07
5.3.30.0170.07014.00
5.3.20.0100.05713.69
5.3.10.0170.06013.90
5.3.00.0100.04713.84
5.2.170.0030.04711.12
5.2.160.0070.05011.25
5.2.150.0130.06011.17
5.2.140.0000.05311.14
5.2.130.0130.05311.07
5.2.120.0030.04711.11
5.2.110.0100.05011.11
5.2.100.0030.05311.10
5.2.90.0100.04711.19
5.2.80.0100.04311.10
5.2.70.0100.05311.10
5.2.60.0000.06311.13
5.2.50.0130.04711.02
5.2.40.0100.04011.10
5.2.30.0100.04310.82
5.2.20.0170.04311.05
5.2.10.0070.05310.96
5.2.00.0070.05710.82
5.1.60.0000.04310.11
5.1.50.0030.0409.97
5.1.40.0100.0439.95
5.1.30.0030.03710.39
5.1.20.0030.05310.34
5.1.10.0070.04710.06
5.1.00.0030.04010.29
5.0.50.0030.0408.61
5.0.40.0070.0308.40
5.0.30.0070.0438.16
5.0.20.0070.0238.30
5.0.10.0030.0338.39
5.0.00.0000.0478.42
4.4.90.0000.0336.89
4.4.80.0030.0236.89
4.4.70.0030.0336.89
4.4.60.0070.0276.89
4.4.50.0030.0236.89
4.4.40.0000.0436.89
4.4.30.0030.0306.89
4.4.20.0000.0306.89
4.4.10.0100.0276.89
4.4.00.0100.0306.89
4.3.110.0030.0236.89
4.3.100.0000.0276.89
4.3.90.0100.0276.89
4.3.80.0070.0406.89
4.3.70.0070.0236.89
4.3.60.0030.0276.89
4.3.50.0030.0236.89
4.3.40.0070.0376.89
4.3.30.0000.0276.89
4.3.20.0030.0276.89
4.3.10.0030.0276.89
4.3.00.0030.0277.14

preferences:
37.03 ms | 401 KiB | 5 Q