3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Variable variable. $a = 'b'; $b = 'target'; var_dump($$a == $b); // Anon function with inclusion of scope. $fn = function($c) { var_dump($$c == 'target'); }; $fn($a); // I can use scope within using variable variable. $fn = fn($c) => $$c == 'target'; var_dump($fn($a)); // I can't return it though. $fn = fn($c) => $$c; var_dump($fn($a));
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
bool(true) Warning: Undefined variable $b in /in/LrCEX on line 9 bool(false) Warning: Undefined variable $b in /in/LrCEX on line 14 bool(false) Warning: Undefined variable $b in /in/LrCEX on line 18 NULL

preferences:
41.81 ms | 407 KiB | 5 Q