14

We often use $class_object->class_procedure or self::class_procedure in PHP OOP. While reading aloud your code, how do you read out these conventions?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ruturaj
  • 143
  • 5

4 Answers4

9

-> is the object operator. Typically called the arrow in conversation. If I were reading the code, I might say:

class object arrow class method

:: is the static resolution operator. I doesn't read as well in conversation. The docs say double colon. I might say:

class colon colon static method

Note: Reading code aloud can be awkward regardless of how you name syntax. Furthermore, it will depend greatly on your audience. I am sharing what I've heard, seen used in books, or found in the docs.

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
  • Yeah, I think I will take this. This goes much in tune with .Net convention where we read "txtText.Text" as "txtText dot Text"... straight as it comes. How about self::proc though? Should I read out "self procedure proc"? – Ruturaj Jan 16 '13 at 03:50
  • *"self double colon proc".* – Jason McCreary Jan 16 '13 at 03:52
  • 2
    I have never heard someone say "class object arrow class method" in conversation – iedoc Jan 16 '13 at 03:58
  • 1
    Thanks. Now this will help me in long run... in seminars, presentations and group discussions etc. :-) – Ruturaj Jan 16 '13 at 03:59
  • 1
    @iedoc: I actually may think of a use case for that: let's suppose you have a secretary in your office and you want her to fix something in your code straight on the production server. So you call her and start telling what to put to the file, while blocked by traffic jam. – zerkms Jan 16 '13 at 03:59
  • ok, that's a good point zerkms – iedoc Jan 16 '13 at 04:07
  • Just answering the question. Don't hate. At least I didn't break out the *spaceship*, `<=>`. :) – Jason McCreary Jan 16 '13 at 13:04
4

You could use their token names:

  • -> (Object Operator AKA Arrow)
  • :: (Paamayim Nekudotayim OR Double Colon OR Static Object Operator)

Or just say:

[static] method X of object Y

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
1

Class object's class procedure

Self's class procedure

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
iedoc
  • 2,266
  • 3
  • 30
  • 53
  • "class object's class procedure" O_o --- "class object's" --- is redundant. Object always created as a class instance. "class procedure" -- there is no such term in php. – zerkms Jan 16 '13 at 03:52
  • the class contains the procedure, so you use "'s" to represent possession. It's how i learned it in school, and how i've always said and heard it said – iedoc Jan 16 '13 at 04:04
  • 2
    in php there are no procedures. There are functions and methods. – zerkms Jan 16 '13 at 04:05
  • @zerkms: ...plus `::` doesn't necessarily represent a call to [it]self. – Alix Axel Jan 16 '13 at 04:15
1

For the static version (self::class_procedure), keep it simple.. "double colon"

Brad
  • 159,648
  • 54
  • 349
  • 530
Nick Parsons
  • 8,377
  • 13
  • 48
  • 70