|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2193 Global declared variables not gobal
Submitted: 1999-08-30 10:25 UTC Modified: 1999-08-30 11:08 UTC
From: lemming at k332 dot feld dot cvut dot cz Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Beta 2 OS: Linux 2.0.36
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: lemming at k332 dot feld dot cvut dot cz
New email:
PHP Version: OS:


 [1999-08-30 10:25 UTC] lemming at k332 dot feld dot cvut dot 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:
function Test()
  global $T;
  echo "T=$T\n";


file t2.php:
function Test2()


'php t1.php' gives

'php t2.php' gives
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-30 11:08 UTC] zeev at cvs dot php dot 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.

 [2002-02-19 05:34 UTC] hvalette at free dot fr

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.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 14:01:23 2020 UTC