3v4l.org

run code in 300+ PHP versions simultaneously
<?php $variabel = "globalt scope"; function hentscope($scope) { if($scope === "getglobal") { global $variabel; } elseif($scope === "GLOBAL") { $variabel = $GLOBALS["variabel"]; } elseif($scope === "local") { $variabel = "lokalt scope"; } return $variabel; } // vi kalder så på forskellige måder echo hentscope("getglobal"); // her henter vi variabel fra det globale scope echo hentscope("GLOBAL"); // henter gennem $GLOBALS (superglobal) echo hentscope("local"); // henter variabel fra local scope (sætter egen variabel) - denne skal ikke bruges i dette tilfælde echo hentscope(""); // sucky error, der er ingen variabel i dit scope der hedder variabel ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
globalt scopeglobalt scopelokalt scope Warning: Undefined variable $variabel in /in/tEDHm on line 14
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
globalt scopeglobalt scopelokalt scope Notice: Undefined variable: variabel in /in/tEDHm on line 14
Output for 7.3.32 - 7.3.33
globalt scopeglobalt scopelokalt scope
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.3
globalt scopeglobalt scopelokalt scope Notice: Undefined variable: variabel in /in/tEDHm on line 14

preferences:
216.51 ms | 402 KiB | 329 Q