From:             steemann at globalpark dot de
Operating system: Linux 2.6.12-10-686
PHP version:      5.2.0RC1
PHP Bug Type:     Class/Object related
Bug description:  static variables mess up global vars

Description:
------------
Variables in the global scope seem to keep corrupted when using static  
properties/variables.  
  
The script below has a global variable $not_there which is supposed to be
NULL  
as it is not set. It is NULL when var_dumping it.  
  
Although the variable is not set by the script, the variable value changes
during  
execution so the script evaluates   
if ($not_there["invalid_var"]))  
to true obviously. When printing a hash of the variable ("use_authmodule"
which  
does not exist), the variable seems to be an array but it should be NULL. 

  
btw: magic_quotes_gpc is turned on. 

Reproduce code:
---------------
something::do_something((int) $argv[1]);

// $not_there is really NULL
var_dump($not_there);

// error occurs here: execution should never get inside the if condition
because $not_there is NULL
if ($not_there["invalid_var"])
{
  // will print NULL (which is ok, but execution should never get here if
the value is NULL)
  var_dump($not_there["use_authmodule"]);
  // will print "PATH:Array"
  print "PATH:".$not_there["use_authmodule"];
}

class something
{
  protected static $static_var=array();

  public static function get_object()
  {
    static $object=NULL;
    if ($object===NULL)
      $object=new something;
    return $object;
  }

  public static function do_something($version=0)
  {
    if ($version==0)
    {
      // $argv[1]==0: this will cause the error
      foreach (array("g"=>&$_GET,"p"=>&$_POST,"r"=>&$_REQUEST) as
$var_name=>$super_global)
        self::get_object()->static_var[]=$var_name;
    } // end of version 0

    if ($version==1)
    {
      // $argv[1]==1: this does the same but will not cause the error
      $obj=self::get_object();
      foreach (array("g"=>&$_GET,"p"=>&$_POST,"r"=>&$_REQUEST) as
$var_name=>$super_global)
        $obj->static_var[]=$var_name;
    } // end of version 1
  } // end of do_something method
} // end of class something

Expected result:
----------------
expected result for $argv[1]==0:  
NULL   
  
  
result for $argv[1]==1:  
NULL  
 

Actual result:
--------------
Call the script above on the command line with $argv[1]=0.  
Script execution gets into the "if ($not_there...)" part as the global
variable 
$not_there gets corrupted. 
 
result is:  
NULL 
NULL   
PATH:Array   
  
 
result for $argv[1]=1:  
NULL  
 
 
So the problem does not occur if the script is called with $argv[1] = 1. 
    
The $argv interpretation and actual difference in the code is in method   

do_something() of class "something". 
    
I know the static property $static_var of class "something" should not be 
  
accessed via -> because it is static, but the code worked fine in PHP 5.1 
 
and also works fine when using version 1 ($argv[1]=1). 

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

Reply via email to