php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dkr at mindwerk dot de
New email:
PHP Version: OS:

 

 [2009-12-08 13:51 UTC] dkr at mindwerk dot de
Description:
------------
Hi!
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:
---------------
<?php
error_reporting(E_ALL);

# 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-08 14:26 UTC] colder@php.net
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] jani@php.net
-Type: Feature/Change Request +Type: Documentation Problem -Package: Feature/Change Request +Package: Variables related
 [2011-02-10 16:27 UTC] vrana@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 16:27 UTC] vrana@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2011-02-10 16:28 UTC] vrana@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=308207
Log: Global level is OK for global and static (doc bug #50411)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC