0

What is this -> symbol Called in PHP. I know it can be interpreted as Equal Sign Right Angle Bracket. | can be called Pipe or OR. but my prof was asking the other term to call the -> symbol. It is for assigning a value to a key in array class. does anyone know what this is called?

R.Surya
  • 184
  • 12

1 Answers1

0

This is called the Object Operator. It is used to access properties and methods inside a class, where you put the -> symbol after.

Example from the documentation:

<?php
class foo
{
    function do_foo()
    {
        echo "Doing foo."; 
    }
}

$bar = new foo;
$bar->do_foo();
?>

As you can see, the do_foo() method is located in the foo class. To access the method outside the class, you need to use the -> symbol to access the properties or methods inside the given class.


Information from the PHP documentation:

Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property. See Static Keyword for more information on the difference between static and non-static properties.

Matthijs
  • 2,483
  • 5
  • 22
  • 33
  • Can you provide an official reference for the operator's name? – axiac Dec 25 '18 at 12:02
  • @axiac As far as I can find on the internet, there is no _official_ resource about the `->` symbol (Object Operator) itself. Thats why I mentioned the documentation about objects, because that is the closest information about the symbol. – Matthijs Dec 25 '18 at 12:05
  • The PHP website (http://www.php.net) **is** the official source of truth regarding PHP. It seems they indeed name `->` as the "Object Operator": http://php.net/manual/en/language.oop5.properties.php – axiac Dec 25 '18 at 13:10
  • Thanks for the info. I've mentioned the PHP website as resource. I meant to say with "no official resource" that there is no page about this specific operator. I have updated my answer. – Matthijs Dec 25 '18 at 13:30