Re: [PHP-DEV] deep compare: nesting level too deep

2003-01-24 Thread Vaclav Dvorak
Moriyoshi Koizumi wrote:

On Sat, Jan 25, 2003 at 01:00:53AM +0100, Vaclav Dvorak wrote:


When I try to compare two "child" objects, PHP says: "Fatal error: 
Nesting level too deep - recursive dependency?". Well, yes, it _is_ a 
recursive dependency, but I don't see why PHP could not compare those 
objects anyway? Isn't it possible to tell whether two "names" reference 
the same "variable"? In fact, I'm comparing two references to the very 
same object, so the comparison could stop right there and not compare 
any members of the object.

Are you trying it with ZE2? Compare those objects with "===" not "==".
You'll get the exact result you've expected to see, I suppose.


No, it's PHP 4.2.2. If it's working like this in ZE2, I guess I'm 
satisfied. Trying to backport it would just waste time that can be spent 
on ZE2. :-) EOT.

Vaclav Dvorak  <[EMAIL PROTECTED]>


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] deep compare: nesting level too deep

2003-01-24 Thread Vaclav Dvorak
Hello list,

I seem to have weird kinds of problems. I probably use some very unusual 
ways to program. I wonder if it's good or bad. ;-)

I have an object that has a member variable that is an array whose 
elements are references to other ("child") objects. Those child objects, 
in turn, hold a reference to the "parent" object.

When I try to compare two "child" objects, PHP says: "Fatal error: 
Nesting level too deep - recursive dependency?". Well, yes, it _is_ a 
recursive dependency, but I don't see why PHP could not compare those 
objects anyway? Isn't it possible to tell whether two "names" reference 
the same "variable"? In fact, I'm comparing two references to the very 
same object, so the comparison could stop right there and not compare 
any members of the object.

Vaclav Dvorak  <[EMAIL PROTECTED]>

PS: Any new ideas, opinions or fact on my foreach problem?


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] foreach nastiness with references (bug #21702)

2003-01-22 Thread Vaclav Dvorak
Moriyoshi Koizumi wrote:

Moriyoshi Koizumi wrote:

1) Each time before entering a foreach loop, php first tries to make a 
copy of
 the array being iterated.

2) In case the array variable is either referenceing another variable or
 referenced by another variable, no copy is made here and the original
 array is used instead. Because of this behaviour, the original's 
 internal
 array pointer increases in the loop eventually.

Yes, I understand this. What I don't understand is WHY is it so? Why is 
foreach handling references specially? Why is your point 2) there?

Oh, I found this issue was pointed out pretty long time ago.

- Bug #5052
  http://bugs.php.net/5052

- Bug #5270 (deleted?)
  http://news.php.net/article.php?group=php.dev&article=22668
http://news.php.net/article.php?group=php.dev&article=22672
  http://news.php.net/article.php?group=php.dev&article=22673

[...]

Anyway, please search the database first, in order not to post the
same kind of bug twice.


I did search the database, and indeed I did see that bug (#5052) before 
posting my bug report. In fact, if you read my bug report, you will see 
that I even mention this bug, and yet another one (#14607). The bug you 
now found (#5052) is similar but NOT the same. In fact, it describes the 
opposite behaviour: the reporter there says that nested foreach's on two 
COPIES of the same array don't work, and that he can work around the bug 
by making a reference to the array. In my bug, nested foreach on a copy 
works, but not on a reference.

So there, I'm not such a complete idiot, you know. ;-)

Regards,

Vaclav Dvorak


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] foreach nastiness with references (bug #21702)

2003-01-22 Thread Vaclav Dvorak
Moriyoshi Koizumi wrote:

I tried to answer this question in the bug report page.

[...]

1) Each time before entering a foreach loop, php first tries to make a copy of
   the array being iterated.

2) In case the array variable is either referenceing another variable or
   referenced by another variable, no copy is made here and the original
   array is used instead. Because of this behaviour, the original's internal
   array pointer increases in the loop eventually.


Yes, I understand this. What I don't understand is WHY is it so? Why is 
foreach handling references specially? Why is your point 2) there?

I probably don't see all the consequences (I know little about PHP/Zend 
internals and have found no documentation), but wouldn't the fix be as 
simple as changing the SEPARATE_ZVAL_IF_NOT_REF into SEPARATE_ZVAL on 
line 2251 of Zend/zend_execute.c? URL: 
http://lxr.php.net/source/php4/Zend/zend_execute.c#2251 (search for 
"case ZEND_FE_RESET:" if line numbers shift).

BTW, what's the relation of http://lxr.php.net/source/php4/Zend/ and 
http://lxr.php.net/source/Zend/ ?

Vaclav Dvorak  <[EMAIL PROTECTED]>


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] foreach nastiness with references (bug #21702)

2003-01-21 Thread Vaclav Dvorak
John Coggeshall wrote:

To answer part of your question:

What the documentation means is that 

$val) {
	$val = "newval";
	} 
?>

Will not change every element in the $foo array to "newval". However,
although $foo cannot be modified by modifying $key and $val the internal
array pointer WILL increment as if you were actually working on that
array directly.. So in order to restore the internal array pointer back
to the start of the array you'd need a call to reset($foo) first.

If that's what the documentation means, then the documentation is wrong. 
Just try it. What you say is true ONLY when there's a reference to the 
array, but that isn't mentioned in the docs. Cut'n'paste:


$a = array(1,2,3);
#$r =& $a;
echo "current before foreach: " . current($a) . "\n";
foreach($a as $b) {
echo "- value in cycle: " . $b . "\n";
echo "-- current in cycle: " . current($a) . "\n";
}
echo "current before foreach: " . current($a) . "\n";
?>

Try it, and the delete the hash mark and try again.

Regards,

Vaclav Dvorak


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] foreach nastiness with references (bug #21702)

2003-01-21 Thread Vaclav Dvorak
Hi,

there's a problem with foreach when the array it iterates over is a 
reference or has a reference: contrary to what was clearly written in 
the documentation for over two years until about two months ago, the 
foreach doesn't make a copy of the array, and so nested foreach's don't 
work because the inner foreach moves the array pointer to the end of the 
array already in the first iteration of the outer array.

About two months ago, the documentation was changed, so that now it 
isn't obviously incorrect; rather, it is confusing.

I think that the current foreach behaviour is seriously broken. Foreach 
should never tamper with the internal pointer of the array it iterates 
over, whether it is a reference or not. Nested foreach's should just work.

I filed bug #21702 on this, but you people are way too quick on the 
wontfix trigger: one says Bogus without an explanation, after reopening 
another says Wontfix because of backwards compatibility. He may be 
right, of course, but I would expect some kind of a discussion. This 
_is_ an open source project, right?

Obviously, the bugbase is not a good place for discussions, so I'll try 
it here.

I, personally, find it hard to imagine how someone could knowingly write 
a script that depends on this broken, undocumented behaviour. Is there 
some way to find out? Surely there must have been questions like this 
before. How about releasing a corrected alpha release and seeing if 
anyone complains?

One more thing: whether this bug is fixed or not, the documentation must 
be clarified! I don't know about you, but I simply don't understand what 
it's supposed to say. Quoting: "Note:  Also note that foreach operates 
on a copy of the specified array, not the array itself, therefore the 
array pointer is not modified as with the each()  construct and changes 
to the array element returned are not reflected in the original array. 
However, the internal pointer of the original array is advanced with the 
processing of the array. Assuming the foreach loop runs to completion, 
the array's internal pointer will be at the end of the array."

Regards,

Vaclav Dvorak  <[EMAIL PROTECTED]>


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php