#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98

    Variable _POST or _GET


    Hello everyone,

    I'm mostly curious why this code doesn't work 100%.

    http://192.168.1.100/test.php?variable=value
    PHP Code:
    $test = "some text to test with";
    $print = "test";
    echo $$print;
    $dataLocation = "_GET";
    $keys = array_keys($$dataLocation);
    foreach($_GET as $k => $v){
      echo $k . " => " . $v . "<br>";
    }


    [code=Results]some text to test with
    Notice: Undefined variable: _GET in test.php on line 5
    variable => value[/code]
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,958
    Rep Power
    9397
    auto_globals_jit. When PHP reads your code it sees references to $_GET and $_SESSION and such and makes sure they're available. Since you try to use one before you explicitly mention it there's no guarantee it will actually exist.

    Try this.
    PHP Code:
    // you don't even have to use it
    $_GET;

    $test "some text to test with";
    $print "test";
    echo $
    $print;
    $dataLocation "_GET";
    $keys array_keys($$dataLocation);
    foreach(
    $_GET as $k => $v){
      echo 
    $k " => " $v "<br>";

    Comments on this post

    • ManiacDan agrees
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98
    Unfortunately this quick fix didn't work, but at least I know why it's happening, I think.

    I went so far as to do this at the top of my script:

    PHP Code:
    $_GET['init'] = 'JIT INIT';


    I've also tried:
    PHP Code:
    ini_set('auto_globals_jit', 'Off');


    As well as going into the php.ini file turning it off there and restarting the server. No difference. I also have a var_dump($_GET); and that shows that there is stuff in the $_GET array.
    Last edited by WrinkledCheese; January 18th, 2013 at 12:39 PM.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    From the manual

    Originally Posted by RTFM Requinix
    Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods. The variable $this is also a special variable that cannot be referenced dynamically.

    Comments on this post

    • WrinkledCheese agrees : This is my issue. Thanks! 96 points for your....collection
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,958
    Rep Power
    9397
    You can't ini_set() it on - it's too late in the process.

    What's the exact script you're using to reproduce this problem? Does it involve classes or functions like Dan pointed out?
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98
    Originally Posted by requinix
    You can't ini_set() it on - it's too late in the process.

    What's the exact script you're using to reproduce this problem? Does it involve classes or functions like Dan pointed out?
    It is in a function.

IMN logo majestic logo threadwatch logo seochat tools logo