php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28437 foreach on container object segfaults
Submitted: 2004-05-18 21:01 UTC Modified: 2004-05-18 23:21 UTC
From: fred at argus dot pt Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.0.0RC2 OS: Linux SuSE 9.0
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: fred at argus dot pt
New email:
PHP Version: OS:

 

 [2004-05-18 21:01 UTC] fred at argus dot pt
Description:
------------
If I create an object with a container(array) instance variable, and then use foreach to iterate over the container, then a segfault occurs.  If I copy the container to a temporary variable, and foreach over the temp, the code works fine.
Similar code worked fine in PHP4, and I think 5.0.0RC1.

Reproduce code:
---------------
<?php
class user  {
public $msgs = array();
}
class message {
public $text;
}
$user = new user;

$msg = new message;
$msg->text = "Hello";
$user->msgs[] = $msg;

foreach($user->msgs as $msg) {
	echo "<br>Text is $msg->text";
}
echo "<br>Tests completed";
?>

Expected result:
----------------
Text is Hello
Tests completed

Actual result:
--------------
Blank Screen
Segfault message in main server error log.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-18 21:07 UTC] wez@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.
 [2004-05-18 23:05 UTC] fred at argus dot pt
Amazing, I succeeded in getting a backtrace for the first time.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 16384 (LWP 171)]
0x4076825d in zend_oe () from /usr/local/Zend/lib/Optimizer-2.5.2/php-5.0.0/ZendOptimizer.so
(gdb) bt
#0  0x4076825d in zend_oe () from /usr/local/Zend/lib/Optimizer-2.5.2/php-5.0.0/ZendOptimizer.so
#1  0x4073d68b in zend_oe () from /usr/local/Zend/lib/Optimizer-2.5.2/php-5.0.0/ZendOptimizer.so
#2  0x4073d360 in zend_oe () from /usr/local/Zend/lib/Optimizer-2.5.2/php-5.0.0/ZendOptimizer.so
#3  0x407e8d39 in db_ () from /usr/local/Zend/lib/Debugger-3.5.0/php-5.0.0/ZendDebugger.so
#4  0x40423aa9 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/local/php-5.0.0RC2/Zend/zend.c:1058
#5  0x403ecf61 in php_execute_script (primary_file=0xbffff290) at /usr/local/php-5.0.0RC2/main/main.c:1630
#6  0x40456766 in php_handler (r=0x82c0cf8) at /usr/local/php-5.0.0RC2/sapi/apache2handler/sapi_apache2.c:556
#7  0x080ab65b in ap_run_handler (r=0x82c0cf8) at config.c:152
#8  0x080abbde in ap_invoke_handler (r=0x82c0cf8) at config.c:358
#9  0x0809a7ab in ap_process_request (r=0x82c0cf8) at http_request.c:246
#10 0x080964cc in ap_process_http_connection (c=0x82bc6a8) at http_core.c:250
#11 0x080b551b in ap_run_process_connection (c=0x82bc6a8) at connection.c:42
#12 0x080aa13d in child_main (child_num_arg=0) at prefork.c:609
#13 0x080aa24d in make_child (s=0x8197fe8, slot=0) at prefork.c:649
#14 0x080aa314 in startup_children (number_to_start=5) at prefork.c:721
#15 0x080aa97d in ap_mpm_run (_pconf=0x8195120, plog=0x81cd200, s=0x0) at prefork.c:940
#16 0x080afd9a in main (argc=2, argv=0xbffff5e4) at main.c:617
 [2004-05-18 23:14 UTC] wez@php.net
Remove the ZendOptimizer and try again :)
 [2004-05-18 23:15 UTC] wez@php.net
and the debugger; remove any third party extensions that you didn't compile yourself.
 [2004-05-18 23:17 UTC] fred at argus dot pt
Wez,
I don't think php is in the frame for this.  After a quick look at the backtrace, I uninstalled Zend Studio Server,
and lo and behold the php code now works.  I'll forward the info to Zend
Best regards. . . Fred
 [2004-05-18 23:20 UTC] fred at argus dot pt
Sorry forgot to say thanks. . . Fred
 [2004-05-18 23:21 UTC] wez@php.net
You're welcome ;)
Marking this as bogus, since it wasn't a PHP bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Nov 29 22:00:01 2025 UTC