php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34907 Segfault when overriding class vars in foreach loop
Submitted: 2005-10-18 13:48 UTC Modified: 2005-10-18 15:32 UTC
From: steemann at globalpark dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.0RC3 OS: Linux 2.6.10-5-68
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: steemann at globalpark dot de
New email:
PHP Version: OS:

 

 [2005-10-18 13:48 UTC] steemann at globalpark dot de
Description:
------------
When assigning class variables to the results of a foreach  
loop and using the variables inside the loop, I am getting  
a segfault in 5.1RC3.  
 
The problem occurs for class variables only. When doing the 
same with local variables, it does not crash. It also does 
not crash if the $this->vars["one"] is not used inside the 
foreach loop.  
 
If the foreach loop is used without setting the key for the 
result it also won't crash, e.g.: 
foreach $foo as $this->vars["two"]  
instead of  
foreach $foo as $this->vars["one"]=>$this->vars["two"] 
won't crash. 
 
I know code like this should never be written but Smarty 
actually does a lot of stuff like this so it won't work 
with 5.1.0RC3. 
 

Reproduce code:
---------------
class x
{
  function run()
  {
    $foo=array("0","1");
    foreach ($foo as $this->vars["one"]=>$this->vars["two"])
      var_dump($this->vars["one"]);
  }
}

$x=new x;
$x->run();

Expected result:
----------------
in PHP 5.1.0b3:  
int(0)  
int(1) 

Actual result:
--------------
in PHP 5.1.0RC3:  
int(0) 
NULL 
Speicherzugriffsfehler (segmentation fault) 
 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-18 14:45 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Works perfectly here.
If you still able to reproduce it - please provide more info (like SAPI you're using, gdb backtrace etc).
 [2005-10-18 15:32 UTC] steemann at globalpark dot de
Yes, it worked fine with the CVS snapshot. 
Thank you.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Apr 16 09:00:02 2026 UTC