Jarod Posted December 24, 2009 Share Posted December 24, 2009 How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so! // set_session("username", "user1"); function set_session($session, $username) { eval($_SESSION['$session'] = $_POST['$username']); } Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/ Share on other sites More sharing options...
oni-kun Posted December 24, 2009 Share Posted December 24, 2009 How do I use eval()? Man it's so confusing, I thought I had it at first. It work, but not until I really needed... I used it with a function and it's not doing so! // set_session("username", "user1"); function set_session($session, $username) { eval($_SESSION['$session'] = $_POST['$username']); } Maybe you should look at the eval function and read what it actually does. Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983417 Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 The first thing is that variables are not interpolated within single quotes, besides, you don't need eval for what you are doing. function set_session($session, $postitem) { $_SESSION[$session] = $_POST[$postitem]; } Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983418 Share on other sites More sharing options...
Jarod Posted December 24, 2009 Author Share Posted December 24, 2009 OK wut did I do wrong in this??? Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1 eval(" if( !isset($_SESSION['server']) ) { $_SESSION['server'] = \"Direct TV\"; echo $_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". $_SESSION['server'] .\")\"; } "); Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983433 Share on other sites More sharing options...
Jarod Posted December 24, 2009 Author Share Posted December 24, 2009 OK wut did I do wrong in this??? Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\practices\test\index.php on line 1 eval(" if( !isset($_SESSION['server']) ) { $_SESSION['server'] = \"Direct TV\"; echo $_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". $_SESSION['server'] .\")\"; } "); Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983443 Share on other sites More sharing options...
co.ador Posted December 24, 2009 Share Posted December 24, 2009 What's that you want to do with the EVAL() function? Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983446 Share on other sites More sharing options...
trq Posted December 24, 2009 Share Posted December 24, 2009 What exactly are you trying to do? You don't need eval(). Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983449 Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 $ needs to be escaped inside of double quotes: eval("if( !isset(\$_SESSION['server']) ) { \$_SESSION['server'] = \"Direct TV\"; echo \$_SESSION['server']; } else { echo \"<b>Server</b> already set! (\". \$_SESSION['server'] .\")\"; } "); Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983450 Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 Please do not make repeat posts. Your questions has been answered in your other post. Link to comment https://forums.phpfreaks.com/topic/186209-i-dont-understand-eval-wtfff/#findComment-983452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.