Is this a bug in PHP?
// Output:
Array
(
[0] => apple
[1] => banana
[2] => carrot
)
Array
(
[0] => apple
[1] => banana
[2] => carrot
)
Array
(
[0] => apple
[1] => banana
[2] => banana
)
Two bananas in the last set?! Not what I expected.
Richard
-
Richard K Miller schreef:
> Is this a bug in PHP?
No
>
> $items = array('apple', 'banana', 'carrot');
> print_r($items);
> foreach ($items as &$item) { }
$item is now a reference to the last element of $items.
> print_r($items);
> foreach ($items as $item) { }
And here, the foreach loop writes to
Hi Jill,
$item is now a reference to the last element of $items.
print_r($items);
foreach ($items as $item) { }
And here, the foreach loop writes to $item for each element: thus
assiging that value to the last element of $items.
The last element of $items is 'carrot'. Why does it print appl
Richard, enumerator exhausted, repeat your sub-sequence again you will get it
e.g pointer and pointed
Best Regards
On Wed, Oct 21, 2009 at 7:01 PM, Richard K Miller
wrote:
> Hi Jill,
>
>>> >> $items = array('apple', 'banana', 'carrot');
>>> print_r($items);
>>> foreach ($items as &$item) { }
>>
On 2009-10-21, at 10:40 PM, Richard K Miller wrote:
I don't follow. Is this really the intended behavior? It seems quite
unintuitive that the original array would be modified by *empty*
loops.
It is intended behaviour. Consider your code; at the end of this loop:
$items = array('apple',
I don't follow. Is this really the intended behavior? It seems quite
unintuitive that the original array would be modified by *empty* loops.
Suppose I create an include file that loops through $_GET variables
with references:
foreach ($_GET as &$get) { /* empty loop */ }
Subsequent foreach(
On 22.10.2009 05:37, Richard K Miller wrote:
> Is this a bug in PHP?
Search the bug DB before asking such questions.
http://bugs.php.net/bug.php?id=29992
http://bugs.php.net/bug.php?id=39307
http://bugs.php.net/bug.php?id=40065
http://bugs.php.net/bug.php?id=40654
http://bugs.php.net/bug.php?id=4
On Oct 22, 2009, at 1:42 AM, Antony Dovgal wrote:
On 22.10.2009 05:37, Richard K Miller wrote:
Is this a bug in PHP?
Search the bug DB before asking such questions.
http://bugs.php.net/bug.php?id=29992
http://bugs.php.net/bug.php?id=39307
http://bugs.php.net/bug.php?id=40065
http://bugs.php.
Richard K Miller wrote:
> On Oct 22, 2009, at 1:42 AM, Antony Dovgal wrote:
>
>> On 22.10.2009 05:37, Richard K Miller wrote:
>>> Is this a bug in PHP?
>>
>> Search the bug DB before asking such questions.
>>
>> http://bugs.php.net/bug.php?id=29992
>> http://bugs.php.net/bug.php?id=39307
>> http:/
It is one of these things that make perfect sense when you think about
it a little bit. Yes, it catches some people, just like strpos()
returning character position 0 on a first-char match catches some
people. There is no way to fix things like these without completely
breaking things. If we ha
On 09-10-21 07:47 PM, Marco Tabini wrote:
On 2009-10-21, at 10:40 PM, Richard K Miller wrote:
I don't follow. Is this really the intended behavior? It seems quite
unintuitive that the original array would be modified by *empty* loops.
It is intended behaviour. Consider your code; at the end
Richard K Miller wrote:
>> It is one of these things that make perfect sense when you think about
>> it a little bit. Yes, it catches some people, just like strpos()
>> returning character position 0 on a first-char match catches some
>> people. There is no way to fix things like these without co
It would be arbitrarily breaking an explicit reference. I know I have
code lying around that relies on multiple loops cleaning up a big
complicated multi-level array. I do ugly things with references into
that array and it would completely break if PHP magically deleted my
references whether the
It would be arbitrarily breaking an explicit reference. I know I have
code lying around that relies on multiple loops cleaning up a big
complicated multi-level array. I do ugly things with references into
that array and it would completely break if PHP magically deleted my
references whether the
On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen
wrote:
> • Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle
> nécessité
Discussing endlessly an issue only because you do not understand it is
also an environmental problem, please consider to read the manual and
stop to use every
On Mon, 16 Nov 2009, Mathieu Suen wrote:
> > > It would be arbitrarily breaking an explicit reference. I know I
> > > have code lying around that relies on multiple loops cleaning up a
> > > big complicated multi-level array. I do ugly things with
> > > references into that array and it would
Pierre Joye a écrit :
On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen
wrote:
• Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle
nécessité
Discussing endlessly an issue only because you do not understand it is
also an environmental problem, please consider to read the manual
Hello,
On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen wrote:
> Pierre Joye a écrit :
>
> On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen
>> wrote:
>>
>> • Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle
>>> nécessité
>>>
>>
>> Discussing endlessly an issue only because you do
Etienne Kneuss a écrit :
Hello,
On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen wrote:
Pierre Joye a écrit :
On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen
wrote:
• Pensez à l'environnement, n'imprimez cet e-mail qu'en cas de réelle
nécessité
Discussing endlessly an issue only because y
That's a completely useless discussion, isn't it? Whoever is "right"
with his opinion regarding scoping - nobody will (and nobody would
like to) change PHP's scoping for those reasons as it would break too
much existing code.
2009/11/16 Mathieu Suen :
> Etienne Kneuss a écrit :
>>
>> Hello,
>>
>>
Maybe you find it useless. That is just a discussion. I don't expect PHP
to change thought it should IMHO, especially now that you are
introducing closure. :)
For those who complain about the foreach behavior (including me) that's
typically a scope issue. Doing an automatic unset isn't the rig
Hello,
On Mon, Nov 16, 2009 at 2:51 PM, Mathieu Suen wrote:
> Etienne Kneuss a écrit :
>
> Hello,
>>
>> On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen > >wrote:
>>
>> Pierre Joye a écrit :
>>>
>>> On Mon, Nov 16, 2009 at 12:07 PM, Mathieu Suen
>>>
wrote:
• Pensez à l'environnem
2009/11/16 Mathieu Suen :
> Maybe you find it useless. That is just a discussion. I don't expect PHP to
> change thought it should IMHO, especially now that you are introducing
> closure. :)
>
> For those who complain about the foreach behavior (including me) that's
> typically a scope issue. Doing
Etienne Kneuss a écrit :
Hello,
On Mon, Nov 16, 2009 at 2:51 PM, Mathieu Suen wrote:
Etienne Kneuss a écrit :
Hello,
On Mon, Nov 16, 2009 at 2:10 PM, Mathieu Suen
*SKIP*
Static scoping is closely related to variable declaration. In PHP, there
is
no such thing as a variable declaration st
24 matches
Mail list logo