ID: 2193
Updated by: [EMAIL PROTECTED]
-Reported By: [EMAIL PROTECTED]
+Reported By: [EMAIL PROTECTED]
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] [EMAIL PROTECTED]
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] [EMAIL PROTECTED]
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