ashton321 Posted December 11, 2008 Share Posted December 11, 2008 I have been looking at a few scripts inside CMS like Joomla and keep seeing ->. What does the -> do in PHP? Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/ Share on other sites More sharing options...
gevans Posted December 11, 2008 Share Posted December 11, 2008 it is usually refering to a function from an assigned object Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713177 Share on other sites More sharing options...
ashton321 Posted December 11, 2008 Author Share Posted December 11, 2008 What does that mean? Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713178 Share on other sites More sharing options...
gevans Posted December 11, 2008 Share Posted December 11, 2008 How your php?? imagine you have a class; class animal{ private var $type; function __construct($a){ $this->type = $a; } function getAnimal(){ return $this->type; } } $animalObject = new animal('dog'); echo $animalObject->getAnimal; make sense? Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713180 Share on other sites More sharing options...
ashton321 Posted December 11, 2008 Author Share Posted December 11, 2008 Im new to PHP and can write basic scripts but im starting to learn functions and classes and i guess the problem for me lies in the $this. I have been doing a little reading like class Cart { var $todays_date; var $name; var $owner; var $items = array("VCR", "TV"); function Cart() { $this->todays_date = date("Y-m-d"); $this->name = $GLOBALS['firstname']; /* etc. . . */ } } So the this means for the items in the class above the function are being set? Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713198 Share on other sites More sharing options...
trq Posted December 12, 2008 Share Posted December 12, 2008 A class is an object template. When you instantiate an object, eg; $obj = new myclass; You create an object of the type myclass (in the given example). Now, within your class template $this is used to refer to the object that will be created once your class has been instantiated. Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713201 Share on other sites More sharing options...
trq Posted December 12, 2008 Share Posted December 12, 2008 Should elaberate some more. So, just as you would use $obj (given the above example) to refer to your object from outside of the object, you would use $this to refer to the object from within it. Does that make sense? Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713202 Share on other sites More sharing options...
ashton321 Posted December 12, 2008 Author Share Posted December 12, 2008 Yes it does thank you very much. Also i found this while browsing around. http://www.phpfreaks.com/forums/index.php/topic,95867.0.html Thanks All Link to comment https://forums.phpfreaks.com/topic/136591-solved-simple-php-qustion/#findComment-713204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.