In, PHP, what is the "->" operator called and how do you say it when reading code out loud?
views:
570answers:
12I 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
the official name is "object operator" - T_OBJECT_OPERATOR. I call it "arrow".
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"
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()".
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."
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 ("::").
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"
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".
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.
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.