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

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16

    Losing $var set in first eval() in second eval()


    I have 2 eval()s. The first one sets $login_error and the second one outputs it. The problem is that the second one cannot find $login_error. But! If I use $_POST["login_error"] instead of $login_error in both eval()s it can find it. Why is this??!

    I have Register Globals set to Off in php.ini.

    On a side note, I wrote a function to convert HTML with PHP in it into pure PHP for use in eval(). It's not perfect but it works.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16
    I've found that if I global $login_error; before printing the variable in the second eval() I can access the variable. But according to the PHP manual: http://uk2.php.net/manual/en/function.eval.php I shouldn't have to do this!

    "Also remember that variables given values under eval() will retain these values in the main script afterwards."

    Or does this not include variables that are created in eval()?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16
    Does anyone know of a way to global the variable when you create it? Or is this not possible?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16
    Woops, looks like this doesn't work after all. Someone with a brain please help!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16
    Ok my investigation continues...

    <?php
    $var123 = "work damn you";
    print $var123."<br>";
    global $var123;
    print_r($GLOBALS);
    ?>

    This code is eval()d in my first eval(). When I print $var123 (line 3) the string is output. BUT! When I print_r($GLOBALS) after global $var123, $var123 is found but is a value of "". Please, someone tell me what the hell is going on here!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    101
    Rep Power
    16
    Ok I found the problem. I was eval()ing in a function return. You cannot do this if you want to retain global variables. eval() the output of the function instead
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sweden
    Posts
    122
    Rep Power
    16
    Hey schizofrenic

IMN logo majestic logo threadwatch logo seochat tools logo