tamagraphics Posted March 21, 2007 Share Posted March 21, 2007 I have a general question that I feel like an idiot asking... in the following code snip what does the $this-> for??? I see this kind of thing all the time using the format of $this-> or $this =>??? function cart($cart_id) { $this -> dblink = mysql_connect($this -> hostname, $this -> username, $this -> password); } What is that all about, a new way of assinging a variable or what? Thanks for all the help Link to comment https://forums.phpfreaks.com/topic/43724-solved-general-question/ Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 If you are working in a class $this references that class. for example <?php class cart { function cart($hostname, $username, $password) { $this->hostname = $hostname; $this->username = $username; $this->password = $password; } function get_cart($cart_id) { $this -> dblink = mysql_connect($this -> hostname, $this -> username, $this -> password); } } No works throughout the class by calling the $this->hostname should print the host name. Link to comment https://forums.phpfreaks.com/topic/43724-solved-general-question/#findComment-212280 Share on other sites More sharing options...
tamagraphics Posted March 21, 2007 Author Share Posted March 21, 2007 so is $this -> hostname; the same as $hostname; and $this -> check_quantity($qty) this would run the function called check_quantity() ???? inside the class anyway?? Link to comment https://forums.phpfreaks.com/topic/43724-solved-general-question/#findComment-212283 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 Right, but $hostname is only local to the function it was defined in. Setting it to $this->hostname makes it local to the whole class it is housed in. Link to comment https://forums.phpfreaks.com/topic/43724-solved-general-question/#findComment-212324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.