From:             marcus3v at hotmail dot com
Operating system: Windows 9x/XP
PHP version:      5.2.0
PHP Bug Type:     Unknown/Other Function
Bug description:  ActivePHP - Variable Scope Bug

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.

# Obs.: since this is a PECL issue, it should be posted on the PECL Bug
Tracking System. It was also posted there... I have posted here because it
appears that this extension ( ActivePHP ) have been a little "abandoned":
on "pecl.php.net", the link to the latest package is broken; the only
actual source for the compiled DLL is "pecl4win.php.net"... Thus, by the
way of the uncertainty, I have posted here ( maybe you have some direct
and special contact with the extension's developer... ).

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]' ( ?!... )

-- 
Edit bug report at http://bugs.php.net/?id=39597&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39597&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39597&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39597&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39597&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39597&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39597&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39597&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39597&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39597&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39597&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39597&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39597&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39597&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39597&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39597&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39597&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39597&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39597&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39597&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39597&r=mysqlcfg

Reply via email to