#29687 [NoF-Csd]: By-reference passed value inside foreach() is no longer working

2009-06-11 Thread jakub dot phpbug at horky dot net
 ID:   29687
 User updated by:  jakub dot phpbug at horky dot net
 Reported By:  jakub dot phpbug at horky dot net
-Status:   No Feedback
+Status:   Closed
 Bug Type: Scripting Engine problem
 Operating System: *
 PHP Version:  6CVS-2006-04-28 (snap)
 New Comment:

Yes, the problem appears to be solved in the new version. Thanks.


Previous Comments:


[2007-08-04 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to Open.



[2007-07-27 05:13:50] j...@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi





[2006-04-28 19:21:51] jakub dot phpbug at horky dot net

(Also note that unlike bug #28939, there are _referenced_ arrays in
question.)



[2006-04-28 19:10:44] jakub dot phpbug at horky dot net

Please review the bug. It ISN'T bogus indeed, although it appears so.
The code snippet provided proves that the behavior is really incorrect.
Admit that when you only touch the array (by read-only function such
as key()), you lose your reference-passing? More, you don't lose it in
current cycle but in the NEXT cycle and subsequent? Hmm...

I tested it on today's snap and still the same behavior.

I'm really looking forward to the moment when I can remove the
workaround from all reference-passed foreachs from all of my projects...
thanks.



[2005-06-19 02:00:07] sni...@php.net

See bug #28939




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29687

-- 
Edit this bug report at http://bugs.php.net/?id=29687edit=1



#29687 [Bgs-Opn]: By-reference passed value inside foreach() is no longer working

2006-04-28 Thread jakub dot phpbug at horky dot net
 ID:   29687
 User updated by:  jakub dot phpbug at horky dot net
 Reported By:  jakub dot phpbug at horky dot net
-Status:   Bogus
+Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: *
-PHP Version:  5CVS-2005-6-19
+PHP Version:  6CVS-2006-04-28 (snap)
 New Comment:

Please review the bug. It ISN'T bogus indeed, although it appears so.
The code snippet provided proves that the behavior is really incorrect.
Admit that when you only touch the array (by read-only function such
as key()), you lose your reference-passing? More, you don't lose it in
current cycle but in the NEXT cycle and subsequent? Hmm...

I tested it on today's snap and still the same behavior.

I'm really looking forward to the moment when I can remove the
workaround from all reference-passed foreachs from all of my
projects... thanks.


Previous Comments:


[2005-06-19 02:00:07] [EMAIL PROTECTED]

See bug #28939




[2004-08-15 15:19:47] jakub dot phpbug at horky dot net

Description:

A value passed inside foreach() costruct by reference does not reflect
the changes made to that value when the iterated array is touched by
some array function, like key() or current().

In example below, if you comment out the key() line, it will work OK.

I think that this bug is closely related to the bug #28939.


Reproduce code:
---
?php

$array = array(NO, NO, NO);

foreach($array as $index = $item)
{
  key($array); // there may be also current(), reset(),
   // first(), next(), prev(), foreach etc.
  $item = YES;
  var_dump($item);
}

print_r($array);

?

Expected result:

string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = YES
[2] = YES
)


Actual result:
--
string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = NO
[2] = NO
)






-- 
Edit this bug report at http://bugs.php.net/?id=29687edit=1


#29687 [Opn]: By-reference passed value inside foreach() is no longer working

2006-04-28 Thread jakub dot phpbug at horky dot net
 ID:   29687
 User updated by:  jakub dot phpbug at horky dot net
 Reported By:  jakub dot phpbug at horky dot net
 Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: *
 PHP Version:  6CVS-2006-04-28 (snap)
 New Comment:

(Also note that unlike bug #28939, there are _referenced_ arrays in
question.)


Previous Comments:


[2006-04-28 19:10:44] jakub dot phpbug at horky dot net

Please review the bug. It ISN'T bogus indeed, although it appears so.
The code snippet provided proves that the behavior is really incorrect.
Admit that when you only touch the array (by read-only function such
as key()), you lose your reference-passing? More, you don't lose it in
current cycle but in the NEXT cycle and subsequent? Hmm...

I tested it on today's snap and still the same behavior.

I'm really looking forward to the moment when I can remove the
workaround from all reference-passed foreachs from all of my
projects... thanks.



[2005-06-19 02:00:07] [EMAIL PROTECTED]

See bug #28939




[2004-08-15 15:19:47] jakub dot phpbug at horky dot net

Description:

A value passed inside foreach() costruct by reference does not reflect
the changes made to that value when the iterated array is touched by
some array function, like key() or current().

In example below, if you comment out the key() line, it will work OK.

I think that this bug is closely related to the bug #28939.


Reproduce code:
---
?php

$array = array(NO, NO, NO);

foreach($array as $index = $item)
{
  key($array); // there may be also current(), reset(),
   // first(), next(), prev(), foreach etc.
  $item = YES;
  var_dump($item);
}

print_r($array);

?

Expected result:

string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = YES
[2] = YES
)


Actual result:
--
string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = NO
[2] = NO
)






-- 
Edit this bug report at http://bugs.php.net/?id=29687edit=1


#29165 [Com]: Request variables are being escaped

2004-08-17 Thread jakub dot phpbug at horky dot net
 ID:   29165
 Comment by:   jakub dot phpbug at horky dot net
 Reported By:  guardkarma-php at yahoo dot com
 Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: Mac OS X
 PHP Version:  5.0.0
 New Comment:

Yes, now I wanted to submit a bug regarding this and I found this. I
think it should be at least documented as a change from PHP4, if not
fixed.

The simple fix diff (warning, I didn't check it against various
vulnerabilities regarding to not addslashes()'ing the key...):

http://jakub.horky.net/php5-fix-gpc-keys-quotes.patch


Previous Comments:


[2004-07-21 23:27:36] guardkarma-php at yahoo dot com

This problem also makes PHP 5 not 100% backward 
compatible.



[2004-07-15 22:31:31] itsbrady-php at yahoo dot com

I don't think the bug is bogus, for several reasons:

#1) Any valid form input should be able to map to PHP. Sometimes PHP
isn't the only programming environment present. Sometimes PHP might
have to interoperate with other environments which might have different
variable naming conventions, etc.

#2) The entire reason we chose to use apostrophes in our form variable
names was to work around PHP's remapping from . to _ within variable
names (e.g., foo.var = foo_var). We can't just remap back from
underscore to period to regenerate the original variable name,
because that might remap legitimate uses of the underscore (example,
foo_something.var gets mapped to foo_something_var, and if you tried to
map it back you'd get foo.something.var, which doesn't match).

#3) It used to work fine in all previous versions of PHP we've used
(throughout the PHP 4.x series).

#4) We certainly do not want PHP to create Global variables like
$foo'var - that would be nuts. We just want to access a perfectly valid
key in a hash - $_REQUEST[foo'var]. There's no language rule against
any such key, and no real reason not to support variables so named on
forms.



[2004-07-15 11:40:16] [EMAIL PROTECTED]

We don't support variable names with wierd characters, so the result is
undefined.



[2004-07-14 22:52:30] guardkarma-php at yahoo dot com

Description:

When upgrading from php 4.3 to 5.0 and using the same 
php.ini file, form variable names with apostrophe 
characters are now being escaped.

magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off


Reproduce code:
---
// mydomain.com/script.php?variable'name=value
?
print_r($_REQUEST);
?

Expected result:

Array (  [variable'name] = value )

Actual result:
--
Array (  [variable\'name] = value )





-- 
Edit this bug report at http://bugs.php.net/?id=29165edit=1


#29686 [Com]: Bug when using foreach on an array that has been referenced before

2004-08-15 Thread jakub dot phpbug at horky dot net
 ID:   29686
 Comment by:   jakub dot phpbug at horky dot net
 Reported By:  swalk at prp dot physik dot tu-darmstadt dot de
 Status:   Open
 Bug Type: Arrays related
 Operating System: Linux
 PHP Version:  5CVS-2004-08-15 (dev)
 New Comment:

I'm afraid that is caused just by the line
$a = foo;
which re-sets the $a variable to string, so it is no longer an array
and can't be enumerated by next loop...


Previous Comments:


[2004-08-15 12:37:33] swalk at prp dot physik dot tu-darmstadt dot de

Description:

When using foreach with an array that has been referenced before, it
behaves oddly if you re-set the variable inside the loop - it loses the
array it originally worked on. That doesn't happen if you leave the line
creating the reference out.

Reproduce code:
---
?php
$a = array(1,2,3);
$b = $a; // this line causes the bug
  // $a = $a; does it too
foreach($a as $v) {
print $v\n;
$a = foo; 
}


Expected result:

1
2
3

Actual result:
--
1

Warning: Invalid argument supplied for foreach() in /home/et/test.php
on line 4





-- 
Edit this bug report at http://bugs.php.net/?id=29686edit=1


#29687 [NEW]: By-reference passed value inside foreach() is no longer working

2004-08-15 Thread jakub dot phpbug at horky dot net
From: jakub dot phpbug at horky dot net
Operating system: Windows Server 2003
PHP version:  5CVS-2004-08-15 (dev)
PHP Bug Type: Arrays related
Bug description:  By-reference passed value inside foreach() is no longer working

Description:

A value passed inside foreach() costruct by reference does not reflect the
changes made to that value when the iterated array is touched by some array
function, like key() or current().

In example below, if you comment out the key() line, it will work OK.

I think that this bug is closely related to the bug #28939.


Reproduce code:
---
?php

$array = array(NO, NO, NO);

foreach($array as $index = $item)
{
  key($array); // there may be also current(), reset(),
   // first(), next(), prev(), foreach etc.
  $item = YES;
  var_dump($item);
}

print_r($array);

?

Expected result:

string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = YES
[2] = YES
)


Actual result:
--
string(3) YES
string(3) YES
string(3) YES
Array
(
[0] = YES
[1] = NO
[2] = NO
)


-- 
Edit bug report at http://bugs.php.net/?id=29687edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29687r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29687r=trysnapshot5
Fixed in CVS:   http://bugs.php.net/fix.php?id=29687r=fixedcvs
Fixed in release:   http://bugs.php.net/fix.php?id=29687r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29687r=needtrace
Need Reproduce Script:  http://bugs.php.net/fix.php?id=29687r=needscript
Try newer version:  http://bugs.php.net/fix.php?id=29687r=oldversion
Not developer issue:http://bugs.php.net/fix.php?id=29687r=support
Expected behavior:  http://bugs.php.net/fix.php?id=29687r=notwrong
Not enough info:http://bugs.php.net/fix.php?id=29687r=notenoughinfo
Submitted twice:http://bugs.php.net/fix.php?id=29687r=submittedtwice
register_globals:   http://bugs.php.net/fix.php?id=29687r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29687r=php3
Daylight Savings:   http://bugs.php.net/fix.php?id=29687r=dst
IIS Stability:  http://bugs.php.net/fix.php?id=29687r=isapi
Install GNU Sed:http://bugs.php.net/fix.php?id=29687r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29687r=float


#29686 [Com]: Bug when using foreach on an array that has been referenced before

2004-08-15 Thread jakub dot phpbug at horky dot net
 ID:   29686
 Comment by:   jakub dot phpbug at horky dot net
 Reported By:  swalk at prp dot physik dot tu-darmstadt dot de
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: *
 PHP Version:  5.*
 New Comment:

To [EMAIL PROTECTED]:

 especially the part with Note:  Also note
 that foreach operates on a copy of the specified
 array and not the array itself.

Sorry, but that especially this paragraph is very obscure, because a
subsequent sentence states However, the internal pointer of the
original array is advanced with the processing of the array.

Furthermore, this is partially subject of recently opened bug #28939 or
#28939.

But there I really don't see any problem. Coincidental overwriting of
registered global is IMO really not bug but stupidity of the author :-)


Previous Comments:


[2004-08-15 15:27:49] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Don't use register globals. And don't use it for example because of
this problem.

Second, a reference variable and a normal variable do NOT result in
foreach copying the whole array. Instaed not accessing the data by ref
[foreach($ar as $data)] only results in copying the data. Therefor the
array is still ste same and if you change the array in the loop then
obviously you affect the loop.



[2004-08-15 15:20:05] [EMAIL PROTECTED]

Care to explain why doing $a = $a; before the loop should affect the
behaviour? In my (and some others whom i talked to) opinion that
behaviour is bogus. And if it does make sense, it should be reflected
in the documentation (where it isn't), because this caused someone an
error with a high WTF factor in an application.
Example:
foreach ($_SESSION['something'] as $foo) {
do_something;
$something = foo;
do_something_else;
}
Breaks on a server with register_globals on.




[2004-08-15 15:07:56] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.



[2004-08-15 15:05:48] [EMAIL PROTECTED]

Please read properly before posting. And also read 
http://www.php.net/foreach , especially the part with Note:  Also note
that foreach operates on a copy of the specified array and not the array
itself.

And as was said, it only happens if you do $a = $a; before the foreach
clause. If you don't do it, you get the expected result.



[2004-08-15 14:55:40] jakub dot phpbug at horky dot net

I'm afraid that is caused just by the line
$a = foo;
which re-sets the $a variable to string, so it is no longer an array
and can't be enumerated by next loop...



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29686

-- 
Edit this bug report at http://bugs.php.net/?id=29686edit=1


#29686 [Com]: Bug when using foreach on an array that has been referenced before

2004-08-15 Thread jakub dot phpbug at horky dot net
 ID:   29686
 Comment by:   jakub dot phpbug at horky dot net
 Reported By:  swalk at prp dot physik dot tu-darmstadt dot de
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: *
 PHP Version:  5.*
 New Comment:

Sorry for mistyping the bug numbers: bug #28939 and bug #29687


Previous Comments:


[2004-08-15 15:40:53] jakub dot phpbug at horky dot net

To [EMAIL PROTECTED]:

 especially the part with Note:  Also note
 that foreach operates on a copy of the specified
 array and not the array itself.

Sorry, but that especially this paragraph is very obscure, because a
subsequent sentence states However, the internal pointer of the
original array is advanced with the processing of the array.

Furthermore, this is partially subject of recently opened bug #28939 or
#28939.

But there I really don't see any problem. Coincidental overwriting of
registered global is IMO really not bug but stupidity of the author :-)



[2004-08-15 15:27:49] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Don't use register globals. And don't use it for example because of
this problem.

Second, a reference variable and a normal variable do NOT result in
foreach copying the whole array. Instaed not accessing the data by ref
[foreach($ar as $data)] only results in copying the data. Therefor the
array is still ste same and if you change the array in the loop then
obviously you affect the loop.



[2004-08-15 15:20:05] [EMAIL PROTECTED]

Care to explain why doing $a = $a; before the loop should affect the
behaviour? In my (and some others whom i talked to) opinion that
behaviour is bogus. And if it does make sense, it should be reflected
in the documentation (where it isn't), because this caused someone an
error with a high WTF factor in an application.
Example:
foreach ($_SESSION['something'] as $foo) {
do_something;
$something = foo;
do_something_else;
}
Breaks on a server with register_globals on.




[2004-08-15 15:07:56] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.



[2004-08-15 15:05:48] [EMAIL PROTECTED]

Please read properly before posting. And also read 
http://www.php.net/foreach , especially the part with Note:  Also note
that foreach operates on a copy of the specified array and not the array
itself.

And as was said, it only happens if you do $a = $a; before the foreach
clause. If you don't do it, you get the expected result.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29686

-- 
Edit this bug report at http://bugs.php.net/?id=29686edit=1


#29686 [Com]: Bug when using foreach on an array that has been referenced before

2004-08-15 Thread jakub dot phpbug at horky dot net
 ID:   29686
 Comment by:   jakub dot phpbug at horky dot net
 Reported By:  swalk at prp dot physik dot tu-darmstadt dot de
 Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: *
 PHP Version:  5.*
 New Comment:

Yes, sorry, now I see you are true. When I tested the example above I
didn't try to comment out the line '$b = $a;' so I thought the array
is always using directly from foreach on each loop. So IMHO there is
either badly written documentation or bad implementation (which is btw
relevant to that two bugs I posted before).

BUG UPDATE: Now I noticed that if you first unset() the $a variable
before re-setting it to the string (or anything else), it is working
properly.


Previous Comments:


[2004-08-15 15:44:12] [EMAIL PROTECTED]

I don't use register globals. But there are lots of servers which do.
1st, you're contradicting the Documentation, which clearly states that
the array should be copied: Note:  Also note that foreach operates on
a copy of the specified array and not the array itself.
2nd, you didn't specify the difference between using a reference
variable and a normal variable.
If you do 
foreach($array as $v) {
   array_push($array, 0);
}
modifying the array, it doesn't affect the loop. By your reasoning, it
should?

Please don't bogus it again, because it is either a problem with the
documentation or with the implementation.



[2004-08-15 15:42:29] jakub dot phpbug at horky dot net

Sorry for mistyping the bug numbers: bug #28939 and bug #29687



[2004-08-15 15:40:53] jakub dot phpbug at horky dot net

To [EMAIL PROTECTED]:

 especially the part with Note:  Also note
 that foreach operates on a copy of the specified
 array and not the array itself.

Sorry, but that especially this paragraph is very obscure, because a
subsequent sentence states However, the internal pointer of the
original array is advanced with the processing of the array.

Furthermore, this is partially subject of recently opened bug #28939 or
#28939.

But there I really don't see any problem. Coincidental overwriting of
registered global is IMO really not bug but stupidity of the author :-)



[2004-08-15 15:27:49] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Don't use register globals. And don't use it for example because of
this problem.

Second, a reference variable and a normal variable do NOT result in
foreach copying the whole array. Instaed not accessing the data by ref
[foreach($ar as $data)] only results in copying the data. Therefor the
array is still ste same and if you change the array in the loop then
obviously you affect the loop.



[2004-08-15 15:20:05] [EMAIL PROTECTED]

Care to explain why doing $a = $a; before the loop should affect the
behaviour? In my (and some others whom i talked to) opinion that
behaviour is bogus. And if it does make sense, it should be reflected
in the documentation (where it isn't), because this caused someone an
error with a high WTF factor in an application.
Example:
foreach ($_SESSION['something'] as $foo) {
do_something;
$something = foo;
do_something_else;
}
Breaks on a server with register_globals on.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29686

-- 
Edit this bug report at http://bugs.php.net/?id=29686edit=1