Log in

View Full Version : How is the -> symbol used



ggalan
05-04-2009, 05:03 PM
can anyone explain how to use the -> symbol as in:

<?php $this->lblLogout->Render(); ?>

Nile
05-04-2009, 05:10 PM
The -> characters are used for accessing objects.


<?php
class Write {
function sayHi(){
echo "Hello";
}
}
$var = new Write();
$var->sayHi();
?>

boogyman
05-04-2009, 06:13 PM
The -> characters are used for accessing objects.


more specifically they are to initiate a method.



class YOURCLASS
{
public function FUNC()
{
/* something */
}
public function FTN($tring, $arr)
{
/* something else*/
}
}




$var = new YOURCLASS();
$var->FUNC(); /* initiate the FUNC method of the YOURCLASS class */

$var->FTN('a1', ['z','y','w']);

Rockonmetal
05-04-2009, 10:38 PM
okay, i also was about to ask this question but i saw it was already asked... would this be an appropriate use of it:


function hi($name){
echo $name;
}
"hello"->hi();

?

Nile
05-04-2009, 10:43 PM
No... The symbol is only used for classes(or OOP).

mitchel456
05-09-2009, 06:19 PM
The "->" in PHP is used to access properties and functions of an object. To use it, you'll need an object to use it on, like this:

Create a class (a blueprint for an object):

class helloObject {
public function hi($name) {
echo "Hello " . $name;
}
}

You can save this as a separate file, called helloObject.php. Then, in the script you want to use it in, first create an instance of your object with the "new" operator, and call the function you've defined in helloObject.php, passing it the name you want printed as a parameter:



$object = new helloObject();
$object->hi("Joe");

This will produce the output:
Hello Joe

ggalan, the code you posted is saying that the variable $this has an object called lblLogout as one of its properties, and this object in turn has a function called Render() - this line calls that function.

sumonrn
01-04-2010, 07:22 AM
Thank you guys. This really clears the idea of oop in php.

Now, folks I just want to know how do you pronounce it. You know while working in a team some times you need to read your code. So, is there any standard pronunciation for the symbol " -> "?

:confused:

traq
01-04-2010, 03:32 PM
I just say "arrow." But then, I don't talk about it much (aloud) with other programmers. Of course, I also say "S - Q - L" instead of "sequel."

sumonrn
01-04-2010, 05:55 PM
I just say "arrow." But then, I don't talk about it much (aloud) with other programmers. Of course, I also say "S - Q - L" instead of "sequel."

:o:o:o
Looks like you just wanted to submit a link! I asked "standard pronunciation". Spam!

Nile
01-04-2010, 06:00 PM
"Submit a Link," what does that mean? He gave you an anwer, the link in his signature is his signature, it shows up every time he posts.

I usually say "This variable accesses this class, and returns blah blah blah..." I don't think that there is a standard way to say it.

traq
01-05-2010, 01:40 AM
:o:o:o
Looks like you just wanted to submit a link! I asked "standard pronunciation". Spam!

Well, I didn't have the exact answer you were looking for, but I was trying to be helpful, and I certainly wasn't spamming. I apologize if it seemed that way.

If you're ever worried about spam posts, you can click on the http://www.dynamicdrive.com/forums/images/buttons/report.gif button to report them to the staff. They'll make the determination if it's spam or not and deal with it accordingly. They're pretty good about it. :D