php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38638 Looping of class member using foreach causes segfault
Submitted: 2006-08-29 06:06 UTC Modified: 2006-08-29 08:59 UTC
From: chiujl at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.5 OS: RHEL4 x86_64
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: chiujl at gmail dot com
New email:
PHP Version: OS:

 

 [2006-08-29 06:06 UTC] chiujl at gmail dot com
Description:
------------
This could be related to bug 31942.

When a global array variable is accessed in both the __construct & __get method and subsequently looped using foreach, it causes segmentation fault the second time the variable is accessed.

Reproduce code:
---------------
<?

$data = array(1, 2, 3);

class classA {
  private $properties;
  function __construct () { $this->properties = $GLOBALS["data"]; }
  function __get ($prop)  { return $GLOBALS["data"]; }
}

function loopValues () {
  $a = new classA();
  foreach ($a->values as $i => $v) { }
}

function dumpValues () {
  $a = new classA();
  var_dump($a->values);
}

loopValues();
dumpValues();

?>

Expected result:
----------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}


Actual result:
--------------
Segmentation fault

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-29 07:40 UTC] tony2001@php.net
Please try using this CVS snapshot:

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

Can't reproduce.
 [2006-08-29 08:59 UTC] chiujl at gmail dot com
Verified no problem in the latest 5.2 snapshot.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 24 23:00:02 2025 UTC