3v4l.org

run code in 300+ PHP versions simultaneously
<?php function shenanigans(string &$foo) { return function () use (&$foo) { $foo = 'But this action at a distance is annoying.'; }; $foo = "I can expect it is changed inside function"; } $somestring = "original value"; $fn = shenanigans($somestring); var_dump($somestring); // many lines of code here // many lines of code here // many lines of code here $fn(); var_dump($somestring);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(14) "original value" string(42) "But this action at a distance is annoying."

preferences:
79.77 ms | 1109 KiB | 4 Q