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 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. 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 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. 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:) 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. 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. Link to comment https://forums.phpfreaks.com/topic/227291-beginner-question/#findComment-1172465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.