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 Link to comment https://forums.phpfreaks.com/topic/97898-user-defined-variable-set/ 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 Link to comment https://forums.phpfreaks.com/topic/97898-user-defined-variable-set/#findComment-500891 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 Link to comment https://forums.phpfreaks.com/topic/97898-user-defined-variable-set/#findComment-500896 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 Link to comment https://forums.phpfreaks.com/topic/97898-user-defined-variable-set/#findComment-500899 Share on other sites More sharing options...
therealwesfoster Posted March 26, 2008 Author Share Posted March 26, 2008 Thats exactly what I need, thanks. Link to comment https://forums.phpfreaks.com/topic/97898-user-defined-variable-set/#findComment-500900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.