note 118339 added to reserved.variables.globals
| From: | stevenjeffries at gmail dot com | Date: | Thu, 19 Nov 2015 09:55:20 +0000 |
| Subject: | note 118339 added to reserved.variables.globals | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204185@lists.php.net to get a copy of this message | ||
I ran into the case where I needed to know if my script was in the global scope or not.
You can use $GLOBALS to figure out which case that is:
<?php // file foo.php
$some_unique_prefix_foo = "ok";
if (isset($GLOBALS["some_unique_prefix_foo"])) {
echo "Foo is in global scope.\n";
} else {
echo "Foo is NOT in global scope.\n";
}
unset($some_unique_prefix_foo);
// Inside another file.
function test() {
include "foo.php";
}
test();
?>
Outputs:
Foo is in global scope.
Foo is NOT in global scope.
----
Server IP: 72.52.91.14
Probable Submitter: 68.230.64.113
----
Manual Page -- http://php.net/manual/en/reserved.variables.globals.php
Edit -- https://master.php.net/note/edit/118339
Del: integrated -- https://master.php.net/note/delete/118339/integrated
Del: useless -- https://master.php.net/note/delete/118339/useless
Del: bad code -- https://master.php.net/note/delete/118339/bad+code
Del: spam -- https://master.php.net/note/delete/118339/spam
Del: non-english -- https://master.php.net/note/delete/118339/non-english
Del: in docs -- https://master.php.net/note/delete/118339/in+docs
Del: other reasons-- https://master.php.net/note/delete/118339
Reject -- https://master.php.net/note/reject/118339
Search -- https://master.php.net/manage/user-notes.php