therealwesfoster Posted March 26, 2008 Share Posted March 26, 2008 Here's what I'm trying to do. <?php $do = 100; function setVar($var,$value) { return eval("\$var = $value"); } setVar("do",300); echo $do; // I want it to echo 300. Instead of the original 100 ?> I'm not using the eval right I'm sure. So my question is, how would i be able to set a variable this way? I'm building a class and thats why I'm wanting a function like this. Thanks Quote Link to comment Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 why do you have to use eval I believe you can use pas by reference in that case which is better Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted March 26, 2008 Author Share Posted March 26, 2008 Well how would you do that? This is something I've always wondered about Quote Link to comment Share on other sites More sharing options...
teng84 Posted March 26, 2008 Share Posted March 26, 2008 see this http://us3.php.net/manual/en/language.references.pass.php Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted March 26, 2008 Author Share Posted March 26, 2008 Thats exactly what I need, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.