Forum Moderators: coopster

Message Too Old, No Replies

print r

position of array pointer

         

nyteshade

11:08 am on May 23, 2011 (gmt 0)

10+ Year Member



My understanding is that print_r leaves an array pointer at the end of an array after execution. However, when I code:

$element = current($myArray);
print_r($element);
print_r($myArray);
$element = current($myArray);
print_r($element);

I can see that the current position of the pointer remains at the beginning of the array? I am simply trying to prove to myself that print_r is doing what the php manual says. Can anyone explain what's really happening? Thanks all.

coopster

3:37 pm on May 24, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like a bug to me. Same exact thing reported and patched in 2000:
[bugs.php.net...]
I would submit a report.

coopster

3:57 pm on May 24, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can confirm it works this way as far back as PHP 5.2.8 on a *nix box and as recent as 5.3.6 on a WIN box. Doesn't seem to be operating system specific. I see quite a few array-related bug reports right now too.

nyteshade

5:36 pm on May 24, 2011 (gmt 0)

10+ Year Member



Thanks for the info. I'm running WinXPSP3 with PHP5.3.0. Guess I should upgrade PHP and try again. Peace.

coopster

5:38 pm on May 24, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It won't work. I tested PHP 5.3.6 with the same results. You found a bug.

nyteshade

7:43 pm on May 24, 2011 (gmt 0)

10+ Year Member



Interesting. Please feel free to report the bug to the development team. I'm so backlogged on stuff that I won't be able to upgrade PHP on my end for some days. And thanks for checking it out. Peace.