PHP Arrow Operator

I’ve started the journey to learn more about OOP (Object Oriented Programming) with PHP and have seen the ‘->’ operator used in most of the code I’ve encountered.

Although it seems to be called the Arrow Operator, I can’t find reference to it other than this page on the php.net web site. Granted, I didn’t search all that long.

From my understanding, the PHP Arrow Operator references the method (a fancy name for a function called from within a class) or a property (a fancy name for a variable called from within a class) via a defined class. In English you would be saying, “I want to use this (method or property) from this class. When I see the arrow operator in code, I read it as “from” in my head.

Here’s another statement with an Arrow Operator translated:

$instance = new simpleClass();

Open up a new instance of this class and start using its logic.

echo $instance->exampleFunction();

Look in the class simpleClass and find the function called exampleFunction. Echo the results.


Comments are closed.