Closed Thread Icon

Topic awaiting preservation: What's -> in php do? Pages that link to <a href="https://ozoneasylum.com/backlink?for=27910" title="Pages that link to Topic awaiting preservation: What&amp;#039;s -&amp;gt; in php do?" rel="nofollow" >Topic awaiting preservation: What&#039;s -&gt; in php do?\

 
Author Thread
redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 05-09-2006 23:05

What the heck does -> do in php? For example:

code:
$this->someFunction();



poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 05-09-2006 23:11

In this case it would call the method someFunction() of the local object.
But I presume you should read PHP's fucking manual : Chapter 18. Classes and Objects (PHP 4), and if you're not familiar wii OOP, wikipedia might help

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 05-10-2006 00:19

ah, it's an OOP thing. I wasn't sure what to search for as "->" doesn't cut it. Thanks!

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 05-10-2006 00:43

I think it's called a reference point. In the case you showed, yes, it's an OP reference, calling to a method inside a defined class. It's also used in PHP's open objects. You can, for example, call up a record set using MySQL, and store it in $result. You can then call, say, $resobj = mysql_fetch_object($result) and you will end up with an object with a series of arrays in it, containing each of the records in your result, listed by column name. So, if your columns were ID, FirstName, LastName, you could do:

code:
foreach ($resobj as $recobj)
{
echo $recobj->ID." ";
echo $recobj->FirstName." ";
echo $recobj->LastName."<br />";
}



So, yes, I've pretty much repeated what poi said, and taken it a bit further. Enjoy!


Justice 4 Pat Richard

divinechaos
Nervous Wreck (II) Inmate

From:
Insane since: Dec 2001

posted posted 05-10-2006 09:44

Two notes:

1) You can use reference points for functions and variables, and consecutively.

e.g.:

$this->user->get_profile();

Just remember that one of the benefits of OOP is encapsulation. Also, check out the parts of man php on Magic Methods like __get() and __set(), where you can override reference points.

2) There's also ::, which is the Scope Resolution Operator.

This is mainly for things that don't require an instance.

e.g.

$plural_word = StringHelper:luralize($word);

It tells PHP which scope in which to look (and is therefore aptly named). Use it when the function doesn't need an instance or instance variables to perform a method.

Finally, a note for Tiberius (from a previous discussion), there are in fact actual interfaces in PHP5. Who knew?

Cheers,
DC

« BackwardsOnwards »

Show Forum Drop Down Menu