On Mon, 12 Feb 2007 20:33:08 +0100, Jochem Maas <jochem@xxxxxxxxxxxxx>
wrote:
how should we know with out seeing the iterator_to_array() definition?
iterator_to_array() function is from php.
See http://de2.php.net/manual/en/function.iterator-to-array.php
Here is another testcase.
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";
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php