jblack Posted January 20, 2007 Share Posted January 20, 2007 I have seen -> in many online scripts and I'm just wondering how that works, I'm not all that new to php, but I haven't been able to figure this out. Link to comment Share on other sites More sharing options...
Kristian_C Posted January 20, 2007 Share Posted January 20, 2007 Not quite sure what you are talking about but : $fetch=mysql_fetch_object(mysql_query("SELECT * FROM table WHERE something='something'"));if($fetch->something!=something){echo"Something";} Not quite sure it was the fetch-> you where after but well here it is ->Kristian_C. Link to comment Share on other sites More sharing options...
jblack Posted January 20, 2007 Author Share Posted January 20, 2007 ...But how does the actual "->" work? Link to comment Share on other sites More sharing options...
Escee Posted January 20, 2007 Share Posted January 20, 2007 The -> is to access a method in a class. <?php class Example { public function Hi ( $param ) { return $param; } } ?> Then: $example = new Example;echo $example -> Hi ( 'Hee!' ); Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2007 Share Posted January 22, 2007 In the general sense, it is the operator to access any class member, not just a method. A class is a complex data structure that contains variables, referred to as class properties, and functions, referred to as class methods. A class for a door might look like this: class Door{ var $opened = false; var $locked = false; function open() { $this->opened = true; } function close() { $this->opened = false; } function lock() { $this->locked = true; } function unlock() { $this->locked = false; }} This is just a simple example to illustrate a class (you probably wouldn't have a "Door" class in many applications). You can see that the door class has 2 properties, to indicate if it is opened and locked. There are 4 methods that you can use to open the door, close the door, lock and unlock it. If you are using this class in your application, you would create a new "instance" of this class like this: $red_door = new Door; This creates an object of the Door class and keeps it in the $red_door variable. If you want to close and lock this door, you would use the close and lock methods, and you would access them like this: $red_door->close();$red_door->lock();if ($red_door->locked == true) echo "the door is locked"; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now