views:

570

answers:

12

In, PHP, what is the "->" operator called and how do you say it when reading code out loud?

+4  A: 

I call it the "arrow" operator. EDIT: While reading code, I would say "operator arrow", as in "A operator arrow B". However, usually I will be more specific, i.e. $db->query() == "Run the query on the database". The syntactic names for these this are much less important than their semantic meaning.

Billy3

Billy ONeal
+26  A: 

the official name is "object operator" - T_OBJECT_OPERATOR. I call it "arrow".

stereofrog
Note that the lexical token is not always what that token is usually referred to. For example, ::'s name is the "scope resolution operator" but is listed in that article as `T_DOUBLE_COLON`. I'll +1 to you when I get some more votes :)
Billy ONeal
Well, sounds weird if you read "And after B executes and return the salary, A arrow C". It'll be more like A refers to C.
Ben
Billy's right, most people call the :: a T_PAAMAYIM_NEKUDOTAYIM in casual conversation
Alan Storm
"nice answer"? hey SO folks, why are we so passionate about upvoting quick-n-stupid answers like this? weird...
stereofrog
@stereofrog: Because such "quick and stupid answers" are short, sweet, and answer the question perfectly. Case in point -- we had 4 people here post their opinion regarding this issue before somebody actually got out the docs and checked.
Billy ONeal
+1  A: 

Property operator.

When reading $a->b() or $a->b loud I just say "call b on the $a obj" or "get b from/in/of $a"

Tor Valamo
@Tor, I guess, "Method operator" also.
Marcus Adams
@Marcus Adams - Not really, seeing as methods are just properties that happen to be functions in most languages. In PHP alone though, there's a big distinction, but I'd still call it a property.
Tor Valamo
+4  A: 

Most often, I use some variation on @Tor Valamo's method ("the B method of A" or "A's B method"), but I sometimes say "dot". E.g. "call A dot B()".

sprugman
I always say "a dot b" because that's how it is in pretty much every other language. PHP and non-PHP devs always seem to understand me.
Gareth
Yea, I fall back to "dot" since it accomplishes the same thing as the dot operator in most other languages. The question then becomes, what do you call `->` in C/C++ where it has different functionality from the actual dot operator?
meagar
A: 

The senior PHP developer where I work says "arrow".

$A->B;

When he's telling me to type the above, he'll say, "Dollar A arrow B" or for

$A->B();

"Dollar A arrow B parens."

Marcus Adams
+3  A: 

When reading PHP Code aloud, I don't pronounce the "->" operator. For $db->prepare($query); I mostly say "Db [short pause] prepare query." So I guess I speak it like a comma in a regular sentence.

Same goes for the Paamayim Nekudotayim ("::").

Techpriester
+2  A: 

I call it "thingy"

Kevin Schroeder
+1  A: 

When reading the code to myself, I think of it like a "possessive thing".

For example:

x->value = y->value

would read "x's value equals y's value"

Dan Mantyla
A: 

Harkening back to the Cobol 'in' where you would say "Move 5 to b in a." Most languages today qualify things the other direction.

Yet I would still read $a->b(); as "Call b in a".

Don
A: 

$a->b I call as "param b of $a"

$a->b() I call as "function b of $a"

ganu
A: 

In high school, in our C class, someone decided to call these "street cred" because a->b() was better than using (*a).b() and therefore got more "street cred." To this day, whenever I see an arrow I call it street cred (e.g. a street cred b). Silly, but catchy.

Jerr
But this is PHP not C++
Joe Philllips
A: 

I personally like to be verbose in expressing my code verbally.

IE:

$foo = new Foo();
echo $foo->bar

would read as such:

echo(/print) the bar property of object foo.

It's verbose and more time consuming, but I find if there is a reason for me to be expressing my code verbally, then I probably need to be clear as to what I'm communicating exactly.

Craige
what the heck is Internet Explorer doing in your answer? ;]
Tomasz Kowalczyk
I'm afraid you've lost me, Tomasz. :/ What do you mean?
Craige