128

What do you call this arrow looking -> operator found in PHP?

It's either a minus sign, dash or hyphen followed by a greater than sign (or right chevron).

How do you pronounce it when reading code out loud?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Jake
  • 2,925
  • 5
  • 22
  • 21
  • 1
    In C++ the "->" operator is called "member of pointer" but the PHP "->" operator is actually closer to the "." operator in C++ and that is called "member of object". – Sam Hobbs Dec 04 '16 at 06:58

15 Answers15

136

The official name is "object operator" - T_OBJECT_OPERATOR.

Dharman
  • 30,962
  • 25
  • 85
  • 135
user187291
  • 53,363
  • 19
  • 95
  • 127
  • 9
    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 Apr 06 '10 at 20:52
  • 1
    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 Apr 06 '10 at 20:54
  • 66
    Billy's right, most people call the :: a T_PAAMAYIM_NEKUDOTAYIM in casual conversation – Alana Storm Apr 06 '10 at 20:56
  • Look at the bottom of [PHP: Operators - Manual](http://php.net/manual/en/language.operators.php). Someone said what you said and they got downvoted 81 times. Note that T_OBJECT_OPERATOR is an internal tag; it is not intended for use by users, right? I can't find any documentation of the "->" operator, just examples in the documentation of its use. – Sam Hobbs Dec 04 '16 at 06:53
58

I call it "dart"; as in $Foo->bar() : "Foo dart bar"

Since many languages use "dot" as in Foo.bar(); I wanted a one-syllable word to use. "Arrow" is just too long-winded! ;)

Since PHP uses . "dot" for concatenation (why?) I can't safely say "dot" -- it could confuse.

Discussing with a co-worker a while back, we decided on "dart" as a word similar enough to "dot" to flow comfortably, but distinct enough (at least when we say it) to not be mistaken for a concatenating "dot".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Umbrella
  • 4,733
  • 2
  • 22
  • 31
39

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.

The same goes for the Paamayim Nekudotayim ("::").

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
selfawaresoup
  • 15,473
  • 7
  • 36
  • 47
14

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
  • 1,840
  • 1
  • 22
  • 33
9

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
  • 19,351
  • 35
  • 110
  • 163
  • 5
    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 Apr 06 '10 at 20:57
  • 1
    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? – user229044 Sep 17 '10 at 16:53
4

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
  • 33,261
  • 11
  • 73
  • 81
  • 1
    @Tor, I guess, "Method operator" also. – Marcus Adams Apr 06 '10 at 20:59
  • @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 Apr 12 '10 at 03:31
4

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".

hichris123
  • 10,145
  • 15
  • 56
  • 70
Don
  • 4,583
  • 1
  • 26
  • 33
4
$a->b 

I call as "param b of $a".

$a->b()

I call as "function b of $a".

hichris123
  • 10,145
  • 15
  • 56
  • 70
ganu
  • 41
  • 2
4

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

e.g.:

$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.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Craige
  • 2,882
  • 2
  • 20
  • 28
3

The single arrow can easily be referred verbally as what it means for PHP OOP: Member. So, for $a->var you would say "Object a's member var".

When reading code aloud, it does help to read ahead (lookahead reference, sorry), and know what you may actually be referring to. For instance, let's have the following bit of code:

<?php
  Class MyClass {
    $foo = 0;

    public function bar() {
      return $this->foo;
    }
  }

  $myobject = new MyClass();
  $myobject->bar();
?>

So, if I were to read aloud this code block as a demonstration of code, I would say this:

"Define Class 'MyClass', open-brace. Variable 'foo' equals zero, terminate line. Define public function 'bar' open-close parentheses, open-brace. Return member variable 'foo' of object 'this', terminate line. Close-brace, close-brace. Instantiate new instance of 'MyClass' (no arguments) as variable object 'myobject', terminate line. Call member method 'bar' of object 'myobject', terminate line."

However, if I were reading the code aloud for other students or programmers to copy without a visual, then I would say:

"PHP open tag (full), newline, indent, Class MyClass open-brace, newline. Indent, ['dollar-sign' | 'Object-marker'] foo equals 0, semicolon, newline, newline. public function bar open-close parentheses, open-brace, newline. Indent, return ['dollar-sign' | 'Object-marker'] this arrow foo, semicolon, newline. Reverse-indent, close-brace, newline, reverse-indent, close-brace, newline, newline. ['dollar-sign' | 'Object-marker'] myobject equals new MyClass open-close parentheses, semicolon, newline. ['dollar-sign' | 'Object-marker'] myobject arrow bar open-close parentheses, semicolon, newline. Reverse-indent, PHP close tag."

Where you see ['dollar-sign' | 'Object-marker'], just choose whichever you tend to speak for '$', I switch between the two frequently, just depends on my audience.

So, to sum it up, in PHP, -> refers to a member of an object, be it either a variable, another object, or a method.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user253780
  • 104
  • 1
  • 7
1

I would do it like this:

//Instantiated object variable with the name mono call property name
$mono->name;

//Instantiated object variable with the name mono call method ship
$mono->ship();

In my book (PHP Master by Lorna Mitchell) it's called the object operator.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Julian
  • 4,396
  • 5
  • 39
  • 51
1

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
  • 53,009
  • 9
  • 91
  • 143
1

user187291 has answered the non-subjective question, as for the subjective one, I say "sub". For example, I would pronounce $x->y as "x sub y" - "sub" in this context is short for "subscript". This is more appropriate for array notation; $x['y'] I also pronounce "x sub y". Typically when reading code out loud, I am using my words to identify a line the other developer can see, so the ambiguity has yet to become a problem. I believe the cause is that I view structs/objects and arrays as "collections", and elements thereof are subscripted as in mathematical notation.

Community
  • 1
  • 1
Iiridayn
  • 1,747
  • 21
  • 43
1

Japanese has a convenient particle for this, "no" (の). It is the possessive particle, meaning roughly "relating to the preceding term".

"Fred の badger" means "Fred's badger".

Which is a long way round of saying that at least mentally, and also amongst those who understand Japanese, I tend to differentiate them by reading them as:

$A->B(); // "Call $A's B."
C::D();  // "Call C の D."

But reading both as a possessive "'s" works too, for non-Japanese speakers. You can also flip them and use "of", so "D of C"... but that's kinda awkward, and hard to do it you're reading rapidly because it breaks your linear flow.

If I were dictating, though, perhaps when pair coding and suggesting what to type, I'd refer to the specific characters as "dash-greater-than arrow" and "double-colon" (if i know the person I'm talking to is a PHPophile, I might call that a "paamayim nekudotayim double-colon" the first time, partly because it's a cool in-joke, partly to prevent them from "correcting" me).

Dewi Morgan
  • 1,143
  • 20
  • 31
0

Object. So $a->$b->$c would be 'A object B object c'.

hichris123
  • 10,145
  • 15
  • 56
  • 70
Mbrevda
  • 2,888
  • 2
  • 27
  • 35