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 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 $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here function caesar($str, $n) { $ret = ""; for($i = 0, $l = strlen($str); $i < $l; ++$i) { $c = ord($str[$i]); if (97 <= $c && $c < 123) { $ret.= chr(($c + $n + 7) % 26 + 97); } else if(65 <= $c && $c < 91) { $ret.= chr(($c + $n + 13) % 26 + 65); } else { $ret.= $str[$i]; } } return $ret; } $array = (array) $test; reset($array); $first_key = key($array); //print_r($array[$first_key]); //used this to figure out the count: // http://rumkin.com/tools/cipher/caesar.php $secret = caesar($array[$first_key],13); //print_r('the secret is:'.$secret); $array = array(); //$test->__set($secret , $secret[$secret]['yum']); $test->__set('secret' , $secret[$secret[$secret]]); function a() { return true; } //$arr = array(callback($test)); //$test->__set('secret' , 'callback' ); // end editing here echo $test->run();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/h69Fs:81 Stack trace: #0 {main} thrown in /in/h69Fs on line 81
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/h69Fs:81 Stack trace: #0 {main} thrown in /in/h69Fs on line 81
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: Illegal string offset 'All your Base are belong to us.' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Notice: Trying to access array offset on value of type bool in /in/h69Fs on line 33 Notice: Trying to access array offset on value of type bool in /in/h69Fs on line 33 Fatal error: Uncaught Error: Function name must be a string in /in/h69Fs:35 Stack trace: #0 /in/h69Fs(37): Test->__set('A', true) #1 /in/h69Fs(81): Test->__set('secret', 'A') #2 {main} thrown in /in/h69Fs on line 35
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33
Warning: Illegal string offset 'All your Base are belong to us.' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Fatal error: Uncaught Error: Function name must be a string in /in/h69Fs:35 Stack trace: #0 /in/h69Fs(37): Test->__set('A', true) #1 /in/h69Fs(81): Test->__set('secret', 'A') #2 {main} thrown in /in/h69Fs on line 35
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Warning: Illegal string offset 'All your Base are belong to us.' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 81 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Warning: Illegal string offset 'A' in /in/h69Fs on line 33 Fatal error: Function name must be a string in /in/h69Fs on line 35
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Fatal error: Function name must be a string in /in/h69Fs on line 35
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/h69Fs on line 21
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/h69Fs on line 21
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/h69Fs on line 21
Process exited with code 255.

preferences:
250.92 ms | 401 KiB | 314 Q