3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function bar(string $str){ $str[0] = "b"; var_dump($str); } $str = ""; $str[0] = "b"; var_dump($str); bar(""); $str = "a"; $str[0] = "b"; var_dump($str); $str = "a"; $str[1] = "b"; var_dump($str);
based on S7Hv9
Output for 7.1.0 - 7.2.0
string(1) "b" string(1) "b" string(1) "b" string(2) "ab"
Output for 7.0.0 - 7.0.20
array(1) { [0]=> string(1) "b" } array(1) { [0]=> string(1) "b" } string(1) "b" string(2) "ab"
Output for 5.3.21 - 5.6.28
array(1) { [0]=> string(1) "b" } Catchable fatal error: Argument 1 passed to bar() must be an instance of string, string given, called in /in/5nKmu on line 12 and defined in /in/5nKmu on line 3
Process exited with code 255.