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 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(){ echo 'nearly there! just need to reshuffle the letters now, can set secret too as its not in scope.'; }; $this->closure = $this->closure->bindTo($test); // I dont really understand what this is doing } // $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.96
8.3.30.0040.01119.21
8.3.20.0000.00820.34
8.3.10.0080.00021.82
8.3.00.0040.00422.44
8.2.170.0110.00422.96
8.2.160.0100.00320.35
8.2.150.0070.00724.18
8.2.140.0000.00924.66
8.2.130.0040.00426.16
8.2.120.0070.00319.30
8.2.110.0090.00022.12
8.2.100.0080.00419.38
8.2.90.0050.00319.17
8.2.80.0050.00318.16
8.2.70.0000.00917.63
8.2.60.0060.00318.00
8.2.50.0000.00818.07
8.2.40.0080.00018.16
8.2.30.0070.00018.03
8.2.20.0040.00417.66
8.2.10.0080.00019.54
8.2.00.0000.00717.78
8.1.270.0030.00622.08
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00618.61
8.1.230.0040.00719.23
8.1.220.0080.00017.79
8.1.210.0030.00518.77
8.1.200.0060.00317.48
8.1.190.0030.00617.63
8.1.180.0060.00318.10
8.1.170.0040.00418.64
8.1.160.0040.00421.92
8.1.150.0040.00418.70
8.1.140.0040.00417.43
8.1.130.0030.00517.86
8.1.120.0000.00717.56
8.1.110.0040.00417.46
8.1.100.0000.00717.46
8.1.90.0060.00317.34
8.1.80.0040.00417.49
8.1.70.0000.00817.50
8.1.60.0090.00017.50
8.1.50.0080.00017.58
8.1.40.0000.00717.56
8.1.30.0000.00817.55
8.1.20.0080.00017.74
8.1.10.0040.00417.56
8.1.00.0050.00217.50
8.0.300.0000.00718.77
8.0.290.0000.00717.18
8.0.280.0070.00018.36
8.0.270.0000.00717.23
8.0.260.0000.00816.91
8.0.250.0030.00316.88
8.0.240.0040.00416.99
8.0.230.0000.00717.05
8.0.220.0030.00316.95
8.0.210.0040.00416.83
8.0.200.0070.00016.91
8.0.190.0000.00716.98
8.0.180.0000.00716.98
8.0.170.0040.00417.02
8.0.160.0030.00516.96
8.0.150.0000.00716.88
8.0.140.0040.00416.91
8.0.130.0030.00313.39
8.0.120.0000.00816.93
8.0.110.0040.00416.96
8.0.100.0030.00316.88
8.0.90.0040.00416.77
8.0.80.0030.01316.86
8.0.70.0040.00416.91
8.0.60.0000.00716.98
8.0.50.0020.00516.79
8.0.30.0090.01117.07
8.0.20.0060.01217.40
8.0.10.0040.00417.16
8.0.00.0100.01116.77
7.4.330.0000.00615.00
7.4.320.0060.00016.64
7.4.300.0000.00716.42
7.4.290.0070.00016.52
7.4.280.0070.00016.53
7.4.270.0040.00416.68
7.4.260.0070.00016.41
7.4.250.0000.00716.60
7.4.240.0010.00616.57
7.4.230.0000.00716.42
7.4.220.0070.01016.66
7.4.210.0050.00916.62
7.4.200.0040.00416.61
7.4.190.0020.00516.76
7.4.160.0130.00316.39
7.4.150.0160.00617.40
7.4.140.0090.00917.86
7.4.130.0080.00916.54
7.4.120.0080.01016.61
7.4.110.0100.00716.45
7.4.100.0110.00816.55
7.4.90.0120.00616.50
7.4.80.0120.01219.39
7.4.70.0130.01016.47
7.4.60.0060.01516.57
7.4.50.0080.00016.51
7.4.40.0000.01522.77
7.4.30.0060.01016.62
7.4.00.0050.01114.97
7.3.330.0000.00613.42
7.3.320.0050.00013.37
7.3.310.0040.00416.29
7.3.300.0000.00816.27
7.3.290.0080.00816.36
7.3.280.0050.01116.38
7.3.270.0140.00317.40
7.3.260.0110.00616.49
7.3.250.0100.00716.37
7.3.240.0090.00916.55
7.3.230.0080.00816.45
7.3.210.0150.00316.31
7.3.200.0200.00319.39
7.3.190.0070.01016.54
7.3.180.0060.01216.68
7.3.170.0140.00616.68
7.3.160.0120.00816.67
7.3.120.0050.01214.84
7.3.110.0050.01114.93
7.3.100.0060.00814.76
7.3.90.0050.00415.01
7.3.80.0050.00814.80
7.3.70.0070.00614.75
7.3.60.0030.01114.78
7.3.50.0070.00414.83
7.3.40.0090.00414.81
7.3.30.0030.00914.77
7.3.20.0060.00716.63
7.3.10.0090.00616.75
7.3.00.0070.00616.51
7.2.330.0140.00416.63
7.2.320.0120.00916.95
7.2.310.0100.01316.60
7.2.300.0120.00816.52
7.2.290.0160.00316.51
7.2.250.0030.01415.24
7.2.240.0090.00915.25
7.2.230.0050.01015.12
7.2.220.0060.00914.94
7.2.210.0040.01115.04
7.2.200.0060.00615.05
7.2.190.0060.00315.14
7.2.180.0040.01015.06
7.2.170.0070.00715.05
7.2.160.0040.00815.16
7.2.150.0070.01116.73
7.2.140.0060.01216.93
7.2.130.0040.01417.04
7.2.120.0060.00916.67
7.2.110.0140.00316.95
7.2.100.0060.00916.98
7.2.90.0040.01216.81
7.2.80.0000.00916.70
7.2.70.0070.01116.88
7.2.60.0070.00916.86
7.2.50.0040.01516.89
7.2.40.0060.01317.04
7.2.30.0090.00916.98
7.2.20.0060.01216.66
7.2.10.0030.01616.90
7.2.00.0070.00518.11
7.1.330.0060.01015.76
7.1.320.0060.00615.71
7.1.310.0060.00915.74
7.1.300.0050.00915.68
7.1.290.0080.00615.77
7.1.280.0030.01115.79
7.1.270.0040.00715.84
7.1.260.0070.00815.82
7.1.250.0090.00915.97
7.1.200.0070.00715.80
7.1.100.0040.01118.19
7.1.70.0070.00317.05
7.1.60.0090.01619.82
7.1.50.0070.01816.95
7.1.00.0030.07722.54
7.0.200.0100.00316.77
7.0.140.0030.07321.96
7.0.60.0070.06319.94
7.0.50.0100.07317.70
7.0.40.0070.05320.21
7.0.30.0370.06720.21
7.0.20.0200.04720.12
7.0.10.0270.04320.07
7.0.00.0130.08020.25
5.6.280.0030.07321.09
5.6.210.0000.08320.63
5.6.200.0030.04318.20
5.6.190.0030.04020.48
5.6.180.3400.04720.63
5.6.170.0370.06720.55
5.6.160.0070.07320.45
5.6.150.0130.04318.19
5.6.140.0070.06018.25
5.6.130.0170.07018.24
5.6.120.0170.07321.14
5.6.110.0070.04021.07
5.6.100.0070.06321.06
5.6.90.0030.05021.02
5.6.80.0200.06320.41
5.6.70.0330.07320.41
5.5.350.0030.05320.46
5.5.340.0000.04317.98
5.5.330.0100.04320.27
5.5.320.0230.04720.30
5.5.310.0400.04720.37
5.5.300.0100.07317.96
5.5.290.0000.07718.01
5.5.280.0030.04320.68
5.5.270.0130.06020.70
5.5.260.0000.05720.79
5.5.250.0070.03720.60
5.5.240.0030.04020.29
5.4.450.0230.04319.12
5.4.440.0700.05719.54
5.4.430.0200.06719.54
5.4.420.0170.05719.47
5.4.410.0070.06019.23
5.4.400.0800.00018.84
5.4.390.1000.00018.75
5.4.380.0270.05018.75
5.4.370.0230.04318.63
5.4.360.0170.04718.76
5.4.350.0130.05718.80
5.4.340.0200.04718.84
5.4.320.0020.04112.52
5.4.310.0060.03912.52
5.4.300.0090.03412.52
5.4.290.0050.03912.51
5.4.280.0080.03512.41
5.4.270.0070.05719.00
5.4.260.0170.04718.94
5.4.250.0100.05018.93
5.4.240.0170.07318.74
5.4.230.0170.07718.85
5.4.220.0200.07018.98
5.4.210.0100.08018.94
5.4.200.0200.05318.93
5.4.190.0070.08318.99
5.4.180.0200.06318.75
5.4.170.0070.07018.64
5.4.160.0270.04718.73
5.4.150.0200.05318.64
5.4.140.0100.07716.56
5.4.130.0070.07016.40
5.4.120.0100.06016.47
5.4.110.0000.06716.67
5.4.100.0170.06716.41
5.4.90.0200.06016.45
5.4.80.0130.05016.54
5.4.70.0130.05316.59
5.4.60.0100.06716.46
5.4.50.0230.05716.47
5.4.40.0230.05716.50
5.4.30.0170.06316.47
5.4.20.0200.05316.34
5.4.10.0070.05716.48
5.4.00.0130.04316.03
5.3.290.0080.04412.80
5.3.280.0130.04714.84
5.3.270.0100.05314.63
5.3.260.0170.07714.71
5.3.250.0130.07314.61
5.3.240.0100.05014.53
5.3.230.0170.05014.45
5.3.220.0100.05314.57
5.3.210.0170.04714.62
5.3.200.0130.05714.72
5.3.190.0000.08314.77
5.3.180.0100.07014.65
5.3.170.0100.07014.54
5.3.160.0130.06714.61
5.3.150.0170.05314.57
5.3.140.0070.05714.65
5.3.130.0100.05714.70
5.3.120.0070.06714.74
5.3.110.0100.07714.67
5.3.100.0170.07014.10
5.3.90.0230.03714.12
5.3.80.0130.06314.01
5.3.70.0070.05314.00
5.3.60.0130.06014.00
5.3.50.0130.06314.15
5.3.40.0130.06714.06
5.3.30.0170.06313.76
5.3.20.0100.05713.63
5.3.10.0100.04713.89
5.3.00.0100.05013.84
5.2.170.0070.05311.16
5.2.160.0100.04011.24
5.2.150.0130.04011.15
5.2.140.0030.04311.06
5.2.130.0100.06311.30
5.2.120.0070.05311.07
5.2.110.0030.05311.20
5.2.100.0100.04711.19
5.2.90.0070.05711.20
5.2.80.0100.05711.27
5.2.70.0030.06311.08
5.2.60.0170.03711.15
5.2.50.0070.04011.04
5.2.40.0000.04710.92
5.2.30.0100.04711.07
5.2.20.0130.04010.95
5.2.10.0100.03711.06
5.2.00.0070.04710.92
5.1.60.0030.04710.09
5.1.50.0030.04010.01
5.1.40.0070.03710.07
5.1.30.0070.04010.41
5.1.20.0100.05710.46
5.1.10.0100.03710.15
5.1.00.0030.04310.33
5.0.50.0100.0338.57
5.0.40.0070.0408.43
5.0.30.0100.0438.31
5.0.20.0000.0338.21
5.0.10.0030.0338.16
5.0.00.0070.0438.02
4.4.90.0030.0206.78
4.4.80.0030.0206.78
4.4.70.0070.0206.78
4.4.60.0070.0276.78
4.4.50.0030.0276.78
4.4.40.0070.0306.78
4.4.30.0100.0176.78
4.4.20.0070.0306.78
4.4.10.0000.0336.78
4.4.00.0030.0306.78
4.3.110.0030.0306.78
4.3.100.0000.0276.78
4.3.90.0030.0306.78
4.3.80.0100.0306.78
4.3.70.0070.0276.78
4.3.60.0070.0176.78
4.3.50.0100.0236.78
4.3.40.0000.0406.78
4.3.30.0000.0276.78
4.3.20.0000.0236.78
4.3.10.0030.0306.78
4.3.00.0100.0206.55

preferences:
61.43 ms | 400 KiB | 5 Q