Bug #2193 Updated: Global declared variables not gobal
| From: | hvalette at free dot fr | Date: | Tue, 19 Feb 2002 10:34:54 +0000 |
| Subject: | Bug #2193 Updated: Global declared variables not gobal | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-558@lists.php.net to get a copy of this message | ||
ID: 2193
Updated by: hvalette@free.fr
-Reported By: lemming@k332.feld.cvut.cz
+Reported By: hvalette@free.fr
Status: Closed
Bug Type: Scripting Engine problem
Operating System: Linux 2.0.36
PHP Version: 4.0 Beta 2
New Comment:
Hi,
I have the salme problem.
I'm not a PHP specialist and i can't find any solution.
Have you found a solution for it ?
Could you explain me the fix ?
Thank you in advance.
HV
Previous Comments:
------------------------------------------------------------------------
[1999-08-30 11:08:42] zeev@cvs.php.net
Your code is wrong.
When you include a file from within a function, the included
code is executed in the scope of that function. Thus, when you
include t1.php from Test2(), $T=1 is executed in the scope of
Test2(), and does not become a global variable. For that reason,
global $T inside Test() does not attach to this variable.
------------------------------------------------------------------------
[1999-08-30 10:25:02] lemming@k332.feld.cvut.cz
It may be just "feature", but it is not documented to behave so:
If I include file within a function and that file declares global
variables, they are not really global:
file t1.php:
<?
$T=1;
function Test()
{
global $T;
echo "T=$T\n";
}
Test()
?>
file t2.php:
<?
function Test2()
{
include('t1.php');
}
Test2();
?>
'php t1.php' gives
T=1
'php t2.php' gives
T=
it is (unset).
If I define T global in Test2(), it works - but it requires
Test2 to know which global variables (configuration
etc...) Test() uses...
Michal Kara alias lemming
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=2193&edit=1