3

I have this data structure below, which is a print_r of $_GET:

 Array (
     [url] => search/
     [q] => shirt
     [view_all] => 
     [price_float_GBP] => Array
         (
             [0] => 107
         )
 )

Why does $_GET['price_float_GBP'][0] work but current($_GET['price_float_GBP']) doesn't?

Sorry if this is a newbie question but I don't quite see it.

6
  • 1
    Which PHP version are you using? (Works as expected for 5.3.) Commented Nov 29, 2011 at 16:58
  • 1
    I don't know why that array's internal pointer would have been moved, but does reset() also fail? Commented Nov 29, 2011 at 16:58
  • Also works for me in PHP 5.2. This doesn't seem like it would be a version-related bug issue. Commented Nov 29, 2011 at 17:05
  • Hmmm...I posted a reply to @mario but it was deleted for some reason? I am using PHP 5.1.6. Commented Nov 29, 2011 at 17:11
  • 1
    @Wiseguy: There have been numerous changes with zval stuff after 5.1, and $_GET in particular is build by early init code. But just build a 5.1.0 CGI and I can't reproduce this behaviour. So it might be some code before that. Even though I'm confused how you could set the internal array pointer out of bounds. @crmpicco: Don't you get any error message or notice? Set error_reporting(E_ALL); beforehand. Commented Nov 29, 2011 at 17:13

1 Answer 1

2

According to the manual it's possible the pointer to be beyond the end of the elements list. This can easily happen if you use foreach on that array.

Cheers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.