Jump to content

[SOLVED] General question


tamagraphics

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.