Dermon3 Posted February 10, 2011 Share Posted February 10, 2011 Hi all For example if you see this code: public function __set($varName,$varValue) { $this->$varName = $varValue; if ($varName == "varOne") { $this->varTwo = $this->varOne * 9; } } Why somewhere dollar sign exists and somewhere not: $this->$varName , $this->varTwo ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/ Share on other sites More sharing options...
KevinM1 Posted February 10, 2011 Share Posted February 10, 2011 The red dollar sign is an error. It shouldn't be there. Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172391 Share on other sites More sharing options...
Dermon3 Posted February 10, 2011 Author Share Posted February 10, 2011 Are you sure? Because I have a book and in several example is same thing there Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172405 Share on other sites More sharing options...
KevinM1 Posted February 10, 2011 Share Posted February 10, 2011 Are you sure? Because I have a book and in several example is same thing there Probably just a typo. The 'this' keyword is the only thing which requires the variable-denoting '$'. In fact, I believe you may get a parse error if you have additional '$'s. Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172410 Share on other sites More sharing options...
Dermon3 Posted February 10, 2011 Author Share Posted February 10, 2011 ok, thank you:) Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172412 Share on other sites More sharing options...
acefirefighter Posted February 10, 2011 Share Posted February 10, 2011 class model { protected $_model; function __construct($model) { $this->_model = $model; $this->$model =&new $model; } I think this is a simpler example of what is above. Your just using a variable to set the name of the model, Right? If not how is that wrong and if it is why? This isn't something I am 100% confident on so I am asking too. Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172435 Share on other sites More sharing options...
KevinM1 Posted February 10, 2011 Share Posted February 10, 2011 It almost sounds like you're referring to variable variables (e.g., $$someVarName), which can get confusing, and is something I avoid for that very reason. Quote Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172465 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.