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.

To me the PHP Arrow Operator seems to reference 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).

Here’s a statement with an Arrow Operator translated to English:

$instance = new SimpleClass();

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

$instance->var = ’somevalue’;

For this instance of the class, we’re going to assign the value ’somevalue’ to var. This is now a variable with a value of ’somevalue’ using the logic from our class.


Comments are closed.