note 99166 added to language.variables.scope
| From: | Anonymous at osu1 dot php dot net | Date: | Sat, 31 Jul 2010 11:48:17 +0000 |
| Subject: | note 99166 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171283@lists.php.net to get a copy of this message | ||
You can use the global function to use variables in classes when included. This means you can have a
file such as "MainSettings.php" (Similar to MediaWiki's localsettings) with DB info,
etc.
<?php
require("MainSettings.php");
class Foo {
function Bar() {
global $testVariable;
return $testVariable;
}
}
?>
MainSettings.php:
<?php
$testVariable = "This works!";
?>
Without the global you would get a E_NOTICE saying that $testVariable is undefined.
----
Server IP: 213.229.106.14
Probable Submitter: 86.186.235.193
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/99166
Del: integrated -- https://master.php.net/note/delete/99166/integrated
Del: useless -- https://master.php.net/note/delete/99166/useless
Del: bad code -- https://master.php.net/note/delete/99166/bad+code
Del: spam -- https://master.php.net/note/delete/99166/spam
Del: non-english -- https://master.php.net/note/delete/99166/non-english
Del: in docs -- https://master.php.net/note/delete/99166/in+docs
Del: other reasons-- https://master.php.net/note/delete/99166
Reject -- https://master.php.net/note/reject/99166
Search -- https://master.php.net/manage/user-notes.php