|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50411 less important: global and static in global scope
Submitted: 2009-12-08 13:51 UTC Modified: 2011-02-10 16:27 UTC
From: dkr at mindwerk dot de Assigned: vrana (profile)
Status: Closed Package: Variables related
PHP Version: 5.2.11 OS: linux 2.6.21
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: dkr at mindwerk dot de
New email:
PHP Version: OS:


 [2009-12-08 13:51 UTC] dkr at mindwerk dot de
Either its some documentation problem or a error reporting problem, but "static" and "global" can be used in the global scope, and this makes no sense?
Or is it some kind of: make statics or globalize variables in a file included in a function in another file? if so, close this bugreport and eventually make some documentation for that... :)
thx and greets

Reproduce code:

# The php doc says "A static variable exists only in a local function scope"
# but this does not fail in any way:

static $test = 1;
echo("test for static successfull\n");

# As global does only makes sense within the function, this should fail
# also with some error or something:

global $test2;
echo("test2 for global successfull\n");

Expected result:
Any error message like "The keyword static|global is not allowed in global scope"

Actual result:
test for static successfull
test2 for global successfull


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-08 14:26 UTC]
global scope != at the main scope of your file. Remember that a file could be included in a function's scope. But sure, it doesn't make much sense to have those in the real global scope, not sure it's worth a runtime notice/warning though
 [2010-11-24 10:06 UTC]
-Type: Feature/Change Request +Type: Documentation Problem -Package: Feature/Change Request +Package: Variables related
 [2011-02-10 16:27 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 16:27 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2011-02-10 16:28 UTC]
Automatic comment from SVN on behalf of vrana
Log: Global level is OK for global and static (doc bug #50411)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jan 23 12:01:24 2021 UTC