From: Operating system: Unix PHP version: 5.3.8 Package: SPL related Bug Type: Bug Bug description:Unset obj.prop. thru ArrayAccess while iterating thru ArrayIterator cause error
Description: ------------ Using foreach to iterate object which implements IteratorAggregate and ArrayAccess while iterating with iterator created by ArrayIterator($this) causes error in internal spl_array_update_pos when trying to unset object property thru arrayaccess interface: debug: #0 0x0000000802f9cd2f in spl_array_update_pos (intern=0x80847d778) at /usr/ports/lang/php5/work/php-5.3.8/ext/spl/spl_array.c:101 101 intern->pos_h = pos->h; [New Thread 8016041c0 (LWP 100187/httpd)] (gdb) bt #0 0x0000000802f9cd2f in spl_array_update_pos (intern=0x80847d778) at /usr/ports/lang/php5/work/php-5.3.8/ext/spl/spl_array.c:101 #1 0x0000000802fa00aa in spl_array_next_no_verify (intern=0x80847d778, aht=0x8082764a8) at /usr/ports/lang/php5/work/php-5.3.8/ext/spl/spl_array.c:858 #2 0x0000000802fa0566 in spl_array_it_move_forward (iter=0x808428330) at /usr/ports/lang/php5/work/php-5.3.8/ext/spl/spl_array.c:983 #3 0x0000000803189a25 in ZEND_FE_FETCH_SPEC_VAR_HANDLER (execute_data=0x807a0a268) at zend_vm_execute.h:9014 #4 0x00000008031616aa in execute (op_array=0x803af3d00) at zend_vm_execute.h:107 #5 0x000000080311c307 in zend_call_function (fci=0x7fffffffcc50, fci_cache=0x7fffffffcc20) at /usr/ports/lang/php5/work/php- 5.3.8/Zend/zend_execute_API.c:968 #6 0x0000000802fcd3ee in zif_call_user_func (ht=2, return_value=0x8082bd5d0, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /usr/ports/lang/php5/work/php-5.3.8/ext/standard/basic_functions.c:4772 #7 0x000000080316271c in zend_do_fcall_common_helper_SPEC (execute_data=0x807a09c48) at zend_vm_execute.h:320 #8 0x00000008031636c5 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER (execute_data=0x807a09c48) at zend_vm_execute.h:425 #9 0x00000008031616aa in execute (op_array=0x807af1c50) at zend_vm_execute.h:107 #10 0x000000080312de5d in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/ports/lang/php5/work/php-5.3.8/Zend/zend.c:1236 #11 0x00000008030ad482 in php_execute_script (primary_file=0x7fffffffe5a0) at /usr/ports/lang/php5/work/php-5.3.8/main/main.c:2284 #12 0x0000000803221e45 in php_handler (r=0x803ba40a0) at /usr/ports/lang/php5/work/php-5.3.8/sapi/apache2handler/sapi_apache2.c:669 #13 0x000000000043dd1a in ap_run_handler (r=0x803ba40a0) at config.c:157 #14 0x000000000043e643 in ap_invoke_handler (r=0x803ba40a0) at config.c:376 #15 0x000000000044f9d4 in ap_process_request (r=0x803ba40a0) at http_request.c:282 #16 0x000000000044c7b4 in ap_process_http_connection (c=0x803afa290) at http_core.c:190 #17 0x00000000004475aa in ap_run_process_connection (c=0x803afa290) at connection.c:43 #18 0x0000000000447a2b in ap_process_connection (c=0x803afa290, csd=0x803afa0a0) at connection.c:190 #19 0x0000000000456d85 in child_main (child_num_arg=37) at prefork.c:667 #20 0x0000000000456f3c in make_child (s=0x80161c708, slot=37) at prefork.c:768 #21 0x0000000000457629 in ap_mpm_run (_pconf=0x801615028, plog=0x801647028, s=0x80161c708) at prefork.c:1068 #22 0x000000000042410b in main (argc=2, argv=0x7fffffffeb20) at main.c:739 (gdb) bt full Test script: --------------- class obj implements \ArrayAccess , \IteratorAggregate { public function __construct() { foreach(array("one" => 1, "two" => 2, "three" => 3) as $offset => $value) $this->{$offset} = $value; } public function offsetSet($offset, $value) { $this->{$offset} = $value; } public function offsetExists($offset) { return isset($this->{$offset}); } public function offsetUnset($offset) { unset($this->{$offset}); } public function offsetGet($offset) { return isset($this->{$offset}) ? $this->{$offset} : null; } function getIterator() { return new \ArrayIterator($this); } } $obj = new obj; foreach($obj as $offset => $value) unset($obj[$offset]); print_r($obj); foreach(get_object_vars($obj) as $offset => $value) unset($obj[$offset]); print_r($obj); Expected result: ---------------- obj Object ( ) obj Object ( ) Actual result: -------------- The first foreach cause an internal error second one is ok -- Edit bug report at https://bugs.php.net/bug.php?id=60498&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60498&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60498&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60498&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60498&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60498&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60498&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60498&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60498&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60498&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60498&r=support Expected behavior: https://bugs.php.net/fix.php?id=60498&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60498&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60498&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60498&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60498&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60498&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60498&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60498&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60498&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60498&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60498&r=mysqlcfg