note 63499 added to language.variables.scope

From: Date: Wed, 22 Mar 2006 23:38:35 +0000
Subject: note 63499 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-106397@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/63499 Del: integrated -- http://master.php.net/note/delete/63499/integrated Del: useless -- http://master.php.net/note/delete/63499/useless Del: bad code -- http://master.php.net/note/delete/63499/bad+code Del: spam -- http://master.php.net/note/delete/63499/spam Del: non-english -- http://master.php.net/note/delete/63499/non-english Del: in docs -- http://master.php.net/note/delete/63499/in+docs Del: other reasons-- http://master.php.net/note/delete/63499 Reject -- http://master.php.net/note/reject/63499 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106397) next »