# marco-oweber@xxxxxx / 2007-02-12 23:34:21 +0100: > Why is this happening? Can you confirm this? What has to be done different? > If you don't get these results (sef faults (I still want to get 2,3,4,5,6) > would you mind > telling me which version of php you are using? > > The file is t.php and its appended at the bottom (cat t.php) > > Thanks in advance Marc > > > marc@localhost /tmp $ php t.php > ====================== > tescase is !!0!! > ====================== > are the following two results the same? > 1 :array(2) { > [0]=> > int(5) > [1]=> > int(6) > } > 2 :current element in my_iterator_to_arrayArray > current element in my_iterator_to_array2 > current element in my_iterator_to_array3 > current element in my_iterator_to_array4 > current element in my_iterator_to_array5 > current element in my_iterator_to_array6 > array(6) { > [0]=> > array(3) { > [0]=> > Segmentation fault > > > marc@localhost /tmp $ php t.php > ====================== > tescase is !!1!! > ====================== > are the following two results the same? > 1 :array(2) { > [0]=> > int(5) > [1]=> > int(6) > } > 2 : > > foreach does print what I want (23456), why ? > 2 > 3 > 4 > 5 > 6 > > > running for each the second time results in segfault again. Why ? > Segmentation fault > > > marc@localhost /tmp $ php -v > PHP 5.1.6-pl6-gentoo (cli) (built: Feb 11 2007 02:37:11) > Copyright (c) 1997-2006 The PHP Group > Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies > > > marc@localhost /tmp $ cat t.php > <?php > $testcase = 1; > echo " ======================\n"; > echo " tescase is !!$testcase!!\n"; > echo " ======================\n"; > > function A() > { > $a = func_get_args(); > return new RecursiveArrayIterator(array(func_get_args())); > } > > function my_iterator_to_array($it) > { > echo $it instanceof IteratorAggregate; // doesn't output anything > so result is false. So I don't have to try calling getIterator manually > $res = array(); > while ($it->valid()){ > echo "current element in my_iterator_to_array", > $it->current(),"\n"; > $res[] = $it->current(); > $it->next(); > } > return $res; > } > > echo "are the following two results the same?\n"; > echo "1 :"; > var_dump(iterator_to_array(new RecursiveIteratorIterator( A (A(2) , > A (3,4), A(5,6))))); > echo "2 :"; > if ($testcase == 0) > var_dump(my_iterator_to_array(new RecursiveIteratorIterator( A > (A(2) , A (3,4), A(5,6))))); > > $ri = new RecursiveIteratorIterator( A (A(2) , A (3,4), A(5,6))); > > echo "\n\nforeach does print what I want (23456), why ?\n"; > foreach( $ri as $v) echo "$v\n"; > // why does the second foreach cause a segfault here? > echo "\n\nrunning for each the second time results in segfault > again. Why ?\n"; > foreach( $ri as $v) echo "$v\n"; I get a nice row of ducks: -rw------- 1 roman roman 2109440 Feb 12 23:09 php512.core -rw------- 1 roman roman 2043904 Feb 12 23:09 php513.core -rw------- 1 roman roman 2043904 Feb 12 23:09 php514.core -rw------- 1 roman roman 2043904 Feb 12 23:09 php515.core -rw------- 1 roman roman 2043904 Feb 12 23:09 php516.core -rw------- 1 roman roman 2203648 Feb 12 23:09 php520.core -rw------- 1 roman roman 1966080 Feb 12 23:09 php521.core This is from 5.2.1: #0 zend_std_object_get_class (object=0x7b03d0) at /usr/home/roman/install/php/php-5.2.1/Zend/zend_object_handlers.c:1044 zobj = (zend_object *) 0x8 #1 0x000000000046fe88 in zim_spl_Array_getChildren (ht=8061904, return_value=0x7b05e0, return_value_ptr=0x79dc78, this_ptr=0x7b03f8, return_value_used=1) at /usr/home/roman/install/php/php-5.2.1/ext/spl/spl_array.c:1386 entry = (zval **) 0x7b0268 intern = (spl_array_object *) 0x85c400 #2 0x0000000000517a05 in zend_call_function (fci=0x7fffffffc870, fci_cache=0x7fffffffd018) at /usr/home/roman/install/php/php-5.2.1/Zend/zend_execute_API.c:984 lcname = 0x1 <Address 0x1 out of bounds> i = 4294952784 original_return_value = (zval **) 0x7fffffffc920 calling_symbol_table = (HashTable *) 0xb original_function_state_ptr = (zend_function_state *) 0x7fffffffd018 original_op_array = (zend_op_array *) 0x7fffffffc750 original_opline_ptr = (zend_op **) 0x7fffffffc918 current_scope = (zend_class_entry *) 0x0 calling_scope = (zend_class_entry *) 0x85c400 check_scope_or_static = (zend_class_entry *) 0x0 current_this = (zval *) 0x0 execute_data = {opline = 0x0, function_state = {function_symbol_table = 0x7afbe8, function = 0x85da00, reserved = { 0x800b646e9, 0x7aca18, 0x0, 0x7aca08}}, fbc = 0x0, op_array = 0x0, object = 0x7b03f8, Ts = 0x7fffffffca30, CVs = 0x7fffffffca00, original_in_execution = 0 '\0', symbol_table = 0x7943e8, prev_execute_data = 0x7fffffffd010, old_error_reporting = 0x0} method_name = (zval *) 0x0 params_array = (zval *) 0x0 call_via_handler = 0 fname = 0xb <Address 0xb out of bounds> fname_len = -14512 #3 0x00000000005369db in zend_call_method (object_pp=0x7fffffffc920, obj_ce=0x85c400, fn_proxy=0x0, function_name=0x603ec2 "getchildren", function_name_len=11, retval_ptr_ptr=0x7fffffffc918, param_count=8, arg1=0x0, arg2=0x0) at /usr/home/roman/install/php/php-5.2.1/Zend/zend_interfaces.c:88 fcic = {initialized = 1 '\001', function_handler = 0x85da00, calling_scope = 0x85c400, object_pp = 0x7fffffffc920} result = 8 fci = {size = 72, function_table = 0x51fc4f, function_name = 0x7fffffffc850, symbol_table = 0x0, retval_ptr_ptr = 0x7fffffffc918, param_count = 0, params = 0x7fffffffc840, object_pp = 0x7fffffffc920, no_separation = 1 '\001'} z_fname = {value = {lval = 1, dval = 4.9406564584124654e-324, str = {val = 0x1 <Address 0x1 out of bounds>, len = 8667136}, ht = 0x1, obj = {handle = 1, handlers = 0x844000}}, refcount = 0, type = 0 '\0', is_ref = 0 '\0'} retval = (zval *) 0x844000 function_table = (HashTable *) 0x7b03d0 params = {0x7fffffffc908, 0x7fffffffc910} #4 0x0000000000465b55 in spl_recursive_it_move_forward_ex (object=0x7b0b50, zthis=0x7afe40) at /usr/home/roman/install/php/php-5.2.1/ext/spl/spl_iterators.c:277 iterator = (zend_object_iterator *) 0x85c400 zobject = (zval *) 0x7b03f8 ce = (zend_class_entry *) 0x85c400 retval = (zval *) 0x7b05e0 child = (zval *) 0x7b05e0 sub_iter = (zend_object_iterator *) 0x7b03f8 has_children = 8766464 #5 0x0000000000465ff3 in spl_recursive_it_rewind_ex (object=0x7b0b50, zthis=0x7afe40) at /usr/home/roman/install/php/php-5.2.1/ext/spl/spl_iterators.c:370 sub_iter = (zend_object_iterator *) 0x7b03d0 #6 0x000000000058faf9 in ZEND_FE_RESET_SPEC_CV_HANDLER (execute_data=0x7fffffffd010) at zend_vm_execute.h:19948 opline = (zend_op *) 0x7b43d0 array_ptr = (zval *) 0x7b0088 fe_ht = (HashTable *) 0x7fffffffd0a0 iter = (zend_object_iterator *) 0x7ad330 ce = (zend_class_entry *) 0x844400 is_empty = 8 '\b' #7 0x000000000054256f in execute (op_array=0x7ac910) at zend_vm_execute.h:92 execute_data = {opline = 0x7b43d0, function_state = {function_symbol_table = 0x7afbe8, function = 0x7ac910, reserved = { 0x800b646e9, 0x7aca18, 0x0, 0x7aca08}}, fbc = 0x0, op_array = 0x7ac910, object = 0x0, Ts = 0x7fffffffca30, CVs = 0x7fffffffca00, original_in_execution = 0 '\0', symbol_table = 0x7943e8, prev_execute_data = 0x0, old_error_reporting = 0x0} #8 0x0000000000524db8 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/home/roman/install/php/php-5.2.1/Zend/zend.c:1135 files = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffffffd200, reg_save_area = 0x7fffffffd110}} i = 1 file_handle = (zend_file_handle *) 0x7fffffffea80 orig_op_array = (zend_op_array *) 0x0 orig_retval_ptr_ptr = (zval **) 0x0 local_retval = (zval *) 0x0 #9 0x00000000004e4fe6 in php_execute_script (primary_file=0x7fffffffea80) at /usr/home/roman/install/php/php-5.2.1/main/main.c:1784 realfile = "/usr/home/roman/tmp/marc.weber\000\000W\004c\000\000\000\000\000\000\001\000\000\000\000\000\000\000(\212\000\000\000\000\000x(\212\000\000\000\000\000\000\211t", '\0' <repeats 101 times>, "GR`\000\000\000\000\000\000\001\000\000\000\000\000\000 c\210\000\000\000\000\000\004\000\000\000\000\000\000\000\006\225ü\0171", '\0' <repeats 11 times>, "Đ\236C", '\0' <repeats 45 times>, "\226Żt\000\b\000\000\000 {R\000\000\000\000\000`\201v\000\b\000\000\000Pä˙˙˙\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\t*š\n\000\000\000\000EKA\000\000\000\000"... prepend_file_p = (zend_file_handle *) 0x0 append_file_p = (zend_file_handle *) 0x0 prepend_file = {type = 0 '\0', filename = 0x0, opened_path = 0x0, handle = {fd = 0, fp = 0x0, stream = {handle = 0x0, reader = 0, closer = 0, fteller = 0, interactive = 0}}, free_filename = 0 '\0'} append_file = {type = 0 '\0', filename = 0x0, opened_path = 0x0, handle = {fd = 0, fp = 0x0, stream = {handle = 0x0, reader = 0, closer = 0, fteller = 0, interactive = 0}}, free_filename = 0 '\0'} old_cwd = 0x7fffffffd210 "" retval = 0 #10 0x00000000005aeb54 in main (argc=2, argv=0x7fffffffeb38) at /usr/home/roman/install/php/php-5.2.1/sapi/cli/php_cli.c:1114 pce = (zend_class_entry *) 0x7fffffffe8f0 arg = (zval *) 0x0 ref = (zval *) 0x0 execute_data = {opline = 0x8008670b0, function_state = {function_symbol_table = 0x80074d659, function = 0x1, reserved = { 0x80074c6df, 0x0, 0x7fffffffeb50, 0x7fffffffeb18}}, fbc = 0x7fffffffeb10, op_array = 0xd550b87a, object = 0x1, Ts = 0x0, CVs = 0x0, original_in_execution = 0 '\0', symbol_table = 0x0, prev_execute_data = 0x800742000, old_error_reporting = 0x0} len = 140737488349424 argn = (zval *) 0x0 input = 0x0 index = 140737488350032 argi = (zval *) 0x800872ae0 exit_status = 0 c = 8 file_handle = {type = 2 '\002', filename = 0x7fffffffed38 "tmp/marc.weber", opened_path = 0x0, handle = {fd = 13322976, fp = 0x800cb4ae0, stream = {handle = 0x800cb4ae0, reader = 0x536460 <zend_stream_stdio_reader>, closer = 0x536480 <zend_stream_stdio_closer>, fteller = 0x5364a0 <zend_stream_stdio_fteller>, interactive = 0}}, free_filename = 0 '\0'} behavior = 1 reflection_what = 0x0 orig_optind = 1 orig_optarg = 0x0 arg_free = 0x7fffffffed38 "tmp/marc.weber" arg_excp = (char **) 0x7fffffffc6b0 script_file = 0x7fffffffed38 "tmp/marc.weber" interactive = 0 module_started = 1 request_started = 1 lineno = 1 exec_direct = 0x0 exec_run = 0x0 exec_begin = 0x0 exec_end = 0x0 param_error = 0x0 hide_argv = 0 ini_entries_len = -5904 -- How many Vietnam vets does it take to screw in a light bulb? You don't know, man. You don't KNOW. Cause you weren't THERE. http://bash.org/?255991 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php