note 126779 deleted from language.variables.scope by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 19:37:37 +0000 |
| Subject: | note 126779 deleted from language.variables.scope by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217927@lists.php.net to get a copy of this message | ||
Note Submitter: robertks at gmail dot com
----
Declaring a variable to be global in a function call argument will cause a parse error.
RIGHT:
<?php
$a = 1; // global scope
function test() {
global $a;
echo subtest($a); // works
}
function subtest($argument) {
return $argument + 1;
}
test();
?>
WRONG:
<?php
$a = 1; // global scope
function test() {
echo subtest(global $a); // results in parse error
}
function subtest($argument) {
return $argument + 1;
}
test();
?>