php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57389 Variable Scope
Submitted: 2006-11-22 17:21 UTC Modified: 2017-04-01 21:26 UTC
From: marcus3v at hotmail dot com Assigned:
Status: Wont fix Package: PHPScript (PECL)
PHP Version: 5_2 CVS-2006-11-22 OS: 9x and XP
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:
Package:
Bug Type:
Summary:
From: marcus3v at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-11-22 17:21 UTC] marcus3v at hotmail dot com
Description:
------------
Dear Sirs,

It seems that there is a serious Variable Scope bug when PHP ( v5.2 ) Scripts are executed in the ActivePHP Environment. The problem is as follows:

# 1 -- when a Variable is declared in Global Scope Statements without explicit use of the "$GLOBALS" Array, it not really becomes Global and can't be seen within Functions through the "global" Keyword nor "$GLOBALS";
# 2 -- conversely, a Variable declared with explicit use of "$GLOBALS" in Global Scope Statements can be seen within Functions, but isn't visible for the own Global Scope Statements ( it's required use of "$GLOBALS"... This also occurs when the declaration is done within a Function -- through "$GLOBALS" ).

I have employed a "php5activescript.dll" version 5.2.0.0 ( 53.314bytes. It's that one distributed with the "pecl-5.2.0-Win32.zip" package ) on Windows 9x and XP.

Reproduce code:
---------------
function varsGlbTest()
{
global $varGlb0, $varGlb1;
/*######*/ $WScript->Echo("varsGlbTest() -- varGlb0= '".$varGlb0."'");
/*######*/ $WScript->Echo("varsGlbTest() -- \$GLOBALS['varGlb0']= '".$GLOBALS["varGlb0"]."'");
/*######*/ $WScript->Echo("varsGlbTest() -- varGlb1= '".$varGlb1."'");
$GLOBALS["varGlb2"]="[varGlb2]";
global $varGlb2;
/*######*/ $WScript->Echo("varsGlbTest() -- varGlb2= '".$varGlb2."'");
}


$varGlb0="[varGlb0]";
$GLOBALS["varGlb1"]="[varGlb1]";
/*######*/ $WScript->Echo("[global] -- varGlb0= '".$varGlb0."'");
/*######*/ $WScript->Echo("[global] -- varGlb1= '".$varGlb1."'");
/*######*/ $WScript->Echo("[global] -- \$GLOBALS['varGlb1']= '".$GLOBALS["varGlb1"]."'");
varsGlbTest();
/*######*/ $WScript->Echo("[global] -- varGlb2= '".$varGlb2."'");
/*######*/ $WScript->Echo("[global] -- \$GLOBALS['varGlb2']= '".$GLOBALS["varGlb2"]."'");

Expected result:
----------------
The output should be the following:

# [global] -- varGlb0= '[varGlb0]'
# [global] -- varGlb1= '[varGlb1]'
# [global] -- $GLOBALS['varGlb1']= '[varGlb1]'
# varsGlbTest() -- varGlb0= '[varGlb0]'
# varsGlbTest() -- $GLOBALS['varGlb0']= '[varGlb0]'
# varsGlbTest() -- varGlb1= '[varGlb1]'
# varsGlbTest() -- varGlb2= '[varGlb2]'
# [global] -- varGlb2= '[varGlb2]'
# [global] -- $GLOBALS['varGlb2']= '[varGlb2]'

Actual result:
--------------
The observed output is the following:

# [global] -- varGlb0= '[varGlb0]'
# [global] -- varGlb1= '' ( "varGlb1" is NULL ( it was not yet assigned ) )
# [global] -- $GLOBALS['varGlb1']= '[varGlb1]' ( ?!... )
# varsGlbTest() -- varGlb0= '' ( "varGlb0" is NULL ( has been it assigned to NULL?... ) )
# varsGlbTest() -- $GLOBALS['varGlb0']= '' ( [idem] )
# varsGlbTest() -- varGlb1= '[varGlb1]'
# varsGlbTest() -- varGlb2= '[varGlb2]'
# [global] -- varGlb2= '' ( "varGlb2" is NULL ( it was not yet assigned ) )
# [global] -- $GLOBALS['varGlb2']= '[varGlb2]' ( ?!... )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-01 21:26 UTC] tpunt@php.net
-Status: Open +Status: Wont fix
 [2017-04-01 21:26 UTC] tpunt@php.net
Due to this extension not seeing any activity since 2009, this issue will not be fixed. We are therefore closing this now.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 03:01:23 2020 UTC