note 63500 added to language.variables.scope
| From: | larax at o2 dot pl | Date: | Wed, 22 Mar 2006 23:38:43 +0000 |
| Subject: | note 63500 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106398@lists.php.net to get a copy of this message | ||
About more complex situation using global variables..
Let's say we have two files:
a.php
<?php
function a() {
include("b.php");
}
a();
?>
b.php
<?php
$b = "something";
function b() {
global $b;
$b = "something new";
}
b();
echo $b;
?>
You could expect that this script will return "something new" but no, it will return
"something". To make it working properly, you must add global keyword in $b definition, in
above example it will be:
global $b;
$b = "something";
----
Server IP: 66.163.161.117
Probable Submitter: 83.144.109.48
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- http://master.php.net/note/edit/63500
Del: integrated -- http://master.php.net/note/delete/63500/integrated
Del: useless -- http://master.php.net/note/delete/63500/useless
Del: bad code -- http://master.php.net/note/delete/63500/bad+code
Del: spam -- http://master.php.net/note/delete/63500/spam
Del: non-english -- http://master.php.net/note/delete/63500/non-english
Del: in docs -- http://master.php.net/note/delete/63500/in+docs
Del: other reasons-- http://master.php.net/note/delete/63500
Reject -- http://master.php.net/note/reject/63500
Search -- http://master.php.net/manage/user-notes.php