note 72132 added to language.variables.scope
| From: | undefinedgeek113atgmaildotcom at osu1 dot php dot net | Date: | Thu, 04 Jan 2007 07:32:27 +0000 |
| Subject: | note 72132 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121267@lists.php.net to get a copy of this message | ||
Just an important note: When you call a function in your script, the function has its own
independent variable set and will ignore any variables set outside the function.
<?php
$a = 1;
function foo() {
echo $a;
}
foo(); // shows nothing
?>
Make sure to import all the variables needed in the function declaration.
<?php
$a = 1;
function foo($a) {
echo $a;
}
foo($a); // shows 1
?>
----
Server IP: 64.71.164.2
Probable Submitter: 71.37.54.42
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/72132
Del: integrated -- https://master.php.net/note/delete/72132/integrated
Del: useless -- https://master.php.net/note/delete/72132/useless
Del: bad code -- https://master.php.net/note/delete/72132/bad+code
Del: spam -- https://master.php.net/note/delete/72132/spam
Del: non-english -- https://master.php.net/note/delete/72132/non-english
Del: in docs -- https://master.php.net/note/delete/72132/in+docs
Del: other reasons-- https://master.php.net/note/delete/72132
Reject -- https://master.php.net/note/reject/72132
Search -- https://master.php.net/manage/user-notes.php