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 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); $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 - not a name for a variable I would choose. 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.0110.00416.88
8.3.50.0100.00917.54
8.3.40.0070.00718.84
8.3.30.0040.01118.52
8.3.20.0040.00418.90
8.3.10.0060.00320.67
8.3.00.0030.00719.38
8.2.180.0060.00916.63
8.2.170.0150.00722.96
8.2.160.0090.00621.11
8.2.150.0050.00224.18
8.2.140.0120.00324.66
8.2.130.0040.00426.16
8.2.120.0080.00017.63
8.2.110.0060.01220.79
8.2.100.0070.00417.84
8.2.90.0000.00819.41
8.2.80.0000.00917.97
8.2.70.0030.00617.75
8.2.60.0060.00317.93
8.2.50.0060.00618.07
8.2.40.0000.00818.16
8.2.30.0000.00818.07
8.2.20.0090.00017.66
8.2.10.0040.00417.78
8.2.00.0080.00017.70
8.1.280.0030.01825.92
8.1.270.0000.00724.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00021.35
8.1.230.0040.00817.42
8.1.220.0040.00417.79
8.1.210.0060.00318.77
8.1.200.0000.01017.36
8.1.190.0040.00417.35
8.1.180.0050.00318.10
8.1.170.0000.00818.66
8.1.160.0000.00718.80
8.1.150.0040.00418.55
8.1.140.0000.00817.49
8.1.130.0040.00417.78
8.1.120.0000.00717.55
8.1.110.0000.00917.43
8.1.100.0000.00817.49
8.1.90.0060.00317.53
8.1.80.0000.00717.39
8.1.70.0030.00317.40
8.1.60.0070.00317.68
8.1.50.0030.00617.42
8.1.40.0000.00817.46
8.1.30.0040.00417.57
8.1.20.0030.00517.72
8.1.10.0070.00017.63
8.1.00.0040.00417.43
8.0.300.0030.00518.77
8.0.290.0000.00916.88
8.0.280.0050.00318.36
8.0.270.0030.00317.23
8.0.260.0030.00316.91
8.0.250.0040.00416.91
8.0.240.0040.00416.92
8.0.230.0000.00716.92
8.0.220.0000.00716.93
8.0.210.0030.00316.95
8.0.200.0040.00416.92
8.0.190.0050.00316.89
8.0.180.0040.00416.91
8.0.170.0030.00616.78
8.0.160.0030.00316.83
8.0.150.0040.00416.89
8.0.140.0000.00816.90
8.0.130.0060.00013.41
8.0.120.0080.00016.81
8.0.110.0040.00417.00
8.0.100.0040.00416.97
8.0.90.0000.00716.84
8.0.80.0040.01216.96
8.0.70.0000.00716.82
8.0.60.0050.00316.89
8.0.50.0040.00416.89
8.0.30.0090.01417.20
8.0.20.0120.01017.15
8.0.10.0040.00416.93
8.0.00.0060.01616.55
7.4.330.0050.00013.02
7.4.320.0060.00016.56
7.4.300.0030.00316.65
7.4.290.0050.00216.63
7.4.280.0040.00416.63
7.4.270.0030.00316.59
7.4.260.0000.00513.30
7.4.250.0080.00016.48
7.4.240.0070.00016.65
7.4.230.0000.00716.35
7.4.220.0070.01016.74
7.4.210.0070.00716.60
7.4.200.0040.00416.35
7.4.190.0070.00016.68
7.4.160.0110.00616.59
7.4.150.0040.01516.43
7.4.140.0100.00716.63
7.4.130.0110.00916.52
7.4.120.0130.00516.49
7.4.110.0090.01216.45
7.4.100.0100.01016.59
7.4.90.0170.00716.35
7.4.80.0130.00319.39
7.4.70.0120.00916.71
7.4.60.0100.00716.68
7.4.50.0000.00416.54
7.4.40.0080.00816.29
7.4.30.0160.00016.58
7.4.00.0050.01014.73
7.3.330.0070.00013.17
7.3.320.0050.00013.41
7.3.310.0040.00416.40
7.3.300.0030.00516.27
7.3.290.0120.00616.32
7.3.280.0080.00816.39
7.3.270.0130.00716.55
7.3.260.0240.00016.53
7.3.250.0120.00616.62
7.3.240.0110.00616.40
7.3.230.0100.00716.43
7.3.210.0090.00916.39
7.3.200.0100.01016.35
7.3.190.0070.01116.39
7.3.180.0100.00716.67
7.3.170.0170.00316.44
7.3.160.0130.00916.67
7.3.120.0060.01014.97
7.3.110.0060.01214.76
7.3.100.0030.01215.03
7.3.90.0070.00315.00
7.3.80.0040.00714.88
7.3.70.0030.01214.86
7.3.60.0060.00614.91
7.3.50.0090.00614.88
7.3.40.0070.00714.84
7.3.30.0080.00414.73
7.3.20.0090.00616.79
7.3.10.0090.00316.37
7.3.00.0130.00416.63
7.2.330.0040.01416.61
7.2.320.0070.01116.85
7.2.310.0030.01716.52
7.2.300.0050.01116.71
7.2.290.0050.01116.58
7.2.250.0060.01214.90
7.2.240.0070.01415.16
7.2.230.0090.00615.07
7.2.220.0070.00415.26
7.2.210.0060.00615.21
7.2.200.0030.00715.15
7.2.190.0120.00015.02
7.2.180.0040.01115.20
7.2.170.0030.00914.96
7.2.130.0100.00716.68
7.2.120.0000.01016.72
7.2.110.0000.01216.81
7.2.100.0070.01016.66
7.2.90.0030.00716.98
7.2.80.0090.00616.82
7.2.70.0060.00616.86
7.2.60.0070.00716.77
7.2.50.0070.00716.93
7.2.40.0030.00716.99
7.2.30.0120.00016.99
7.2.20.0060.00617.05
7.2.10.0080.00416.96
7.2.00.0080.00518.05
7.1.330.0090.00615.69
7.1.320.0000.01115.95
7.1.310.0060.00915.95
7.1.300.0090.00615.54
7.1.290.0070.00715.54
7.1.280.0070.01115.76
7.1.270.0030.01015.82
7.1.260.0100.00315.54
7.1.250.0000.00915.93
7.1.100.0000.01417.96
7.1.70.0040.00417.12
7.1.60.0030.02019.40
7.1.50.0130.01016.85
7.1.00.0030.08022.42
7.0.200.0900.00014.82
7.0.140.0100.06722.08
7.0.120.0030.07322.09
7.0.60.0100.05320.02
7.0.50.0070.08017.86
7.0.40.0100.06320.24
7.0.30.0270.07320.30
7.0.20.0130.05020.07
7.0.10.0000.09320.25
7.0.00.0070.04320.07
5.6.280.0070.07021.16
5.6.210.0130.05720.75
5.6.200.0070.05018.18
5.6.190.0070.09020.47
5.6.180.0270.03720.48
5.6.170.0230.04320.45
5.6.160.0100.06720.50
5.6.150.0070.05318.29
5.6.140.0100.07718.18
5.6.130.0070.08318.19
5.6.120.0070.07021.04
5.6.110.0030.09021.00
5.6.100.0100.04321.02
5.6.90.0030.05720.98
5.6.80.0070.08020.51
5.6.70.3500.04720.30
5.5.350.0430.06020.43
5.5.340.0070.08017.94
5.5.330.0030.04720.20
5.5.320.0200.04020.52
5.5.310.0200.04720.19
5.5.300.0030.04318.09
5.5.290.0000.08018.04
5.5.280.0030.04320.89
5.5.270.0070.09020.82
5.5.260.0030.08720.98
5.5.250.0000.09020.60
5.5.240.0270.06320.21
5.4.450.0370.06719.20
5.4.440.0370.05319.27
5.4.430.0200.06719.48
5.4.420.0270.07319.45
5.4.410.0230.04719.20
5.4.400.0170.06719.00
5.4.390.0200.07719.16
5.4.380.0170.05719.22
5.4.370.0170.07719.00
5.4.360.0200.05319.13
5.4.350.0170.06318.86
5.4.340.0300.06319.09
5.4.320.0200.06019.32
5.4.310.0270.06019.32
5.4.300.0230.04319.30
5.4.290.0170.08319.13
5.4.280.0330.06719.19
5.4.270.0270.04319.31
5.4.260.0230.06018.87
5.4.250.0400.06718.98
5.4.240.0370.06319.30
5.4.230.0230.04718.87
5.4.220.0300.05319.09
5.4.210.0230.07318.93
5.4.200.0330.06319.16
5.4.190.0200.08019.30
5.4.180.0270.05719.13
5.4.170.0230.05719.23
5.4.160.0270.06718.85
5.4.150.0270.06018.99
5.4.140.0230.04316.43
5.4.130.0330.04316.54
5.4.120.0200.07716.50
5.4.110.0230.06716.41
5.4.100.0200.05716.41
5.4.90.0300.06316.40
5.4.80.0230.06716.49
5.4.70.0270.05716.50
5.4.60.0230.06716.54
5.4.50.0130.07316.49
5.4.40.0170.03716.55
5.4.30.0170.03316.55
5.4.20.0100.03716.54
5.4.10.0130.03716.27
5.4.00.0130.03315.87
5.3.290.0170.05314.86
5.3.280.0300.06714.86
5.3.270.0200.07714.86
5.3.260.0200.06714.86
5.3.250.0270.06714.86
5.3.240.0200.06714.86
5.3.230.0270.04714.86
5.3.220.0130.06714.86
5.3.210.0200.07714.86
5.3.200.0230.08014.86
5.3.190.0270.03714.86
5.3.180.0200.07314.86
5.3.170.0300.07314.86
5.3.160.0270.06314.86
5.3.150.0230.07314.86
5.3.140.0170.05014.86
5.3.130.0130.03714.86
5.3.120.0200.03314.86
5.3.110.0130.03714.86
5.3.100.0130.03714.86
5.3.90.0170.04014.86
5.3.80.0070.04314.86
5.3.70.0130.03714.86
5.3.60.0100.04014.86
5.3.50.0070.04314.86
5.3.40.0100.04014.86
5.3.30.0130.05714.86
5.3.20.0170.03014.86
5.3.10.0130.03714.86
5.3.00.0170.03014.86
5.2.170.0170.03014.86
5.2.160.0070.03314.86
5.2.150.0100.04714.86
5.2.140.0100.03314.86
5.2.130.0070.03314.86
5.2.120.0100.02714.86
5.2.110.0170.02714.86
5.2.100.0070.03314.86
5.2.90.0130.02714.86
5.2.80.0130.03014.86
5.2.70.0100.03014.86
5.2.60.0130.02714.86
5.2.50.0100.03014.86
5.2.40.0000.04014.86
5.2.30.0100.02714.86
5.2.20.0070.03014.86
5.2.10.0100.02714.86
5.2.00.0070.03314.86
5.1.60.0130.02314.86
5.1.50.0170.01714.86
5.1.40.0100.02314.86
5.1.30.0130.02014.86
5.1.20.0100.02314.86
5.1.10.0030.03014.86
5.1.00.0070.02714.86
5.0.50.0100.02014.86
5.0.40.0070.01714.86
5.0.30.0100.03014.86
5.0.20.0030.02014.86
5.0.10.0030.02014.86
5.0.00.0070.05014.86
4.4.90.0030.01714.86
4.4.80.0030.01714.86
4.4.70.0030.01714.86
4.4.60.0030.01714.86
4.4.50.0070.01314.86
4.4.40.0030.02714.86
4.4.30.0030.01714.86
4.4.20.0030.01714.86
4.4.10.0070.02014.86
4.4.00.0070.02314.86
4.3.110.0070.01314.86
4.3.100.0030.01714.86
4.3.90.0000.01714.86
4.3.80.0070.05014.86
4.3.70.0070.03714.86
4.3.60.0130.02714.86
4.3.50.0070.02714.86
4.3.40.0070.03314.86
4.3.30.0070.03314.86
4.3.20.0030.03714.86
4.3.10.0100.02014.86
4.3.00.0070.02714.86

preferences:
58.12 ms | 400 KiB | 5 Q