What does php sign mean ->
  • Thanks to everyone who responded. Now it is more or less clear, but rather on an intuitive level))) - deskolada

3 answers 3

In the manual, it is called "object operator" - T_OBJECT_OPERATOR. Apparently used to call non-static class methods.

Method chaining is read left to right (left associative): <?php class Test_Method_Chain { public function One() { echo "One" . PHP_EOL; return $this; } public function Two() { echo "Two" . PHP_EOL; return $this; } public function Three() { echo "Three" . PHP_EOL; return $this; } } $test = new Test_Method_Chain(); $test->One()->Two()->Three(); /* Ouputs: One Two Three */ ?> 
  • Thank) - deskolada
  • Writing $ test-> One () -> Two () -> Three () is possible because the methods being called return an object of the same class. Anywhere such a call will not work. Also, this use option is available only from a specific version of php (probably from 5.3), previously dereferencing an object (getting a link to it) was not available in this form and required entering an additional intermediate variable. $ a = $ test-> One (); $ b = $ a-> Two (); $ c = $ b-> Three (); - nMike

Yes. Exactly. To call methods and properties. In Java and c # if I'm not mistaken, this is the point.

  • And in javascript - atnartur
  • and in delphi a point, but in C ++ as in php -> - vdk company
  • 2
    @savro You're so vain about C++ :) - Costantino Rupert
  • myclass.method () is C ++, do not confuse the person. myclass-> method () is also C ++, but here myclass is a pointer, not an object or a link. - user6550
  • one
    A small training snippet clearly illustrating the statements of previous authors about C ++ myclass myclassobject; myclass * myclassobjectpointer = & myclassobject; myclassobject.method (); myclassobjectpointer-> method (); myclass :: staticmethod (); - igumnov

It is used not only to call non-static methods, but also to refer to the properties (fields) of an object (and not a class).

In general, as far as I know, it was moved from C ++. At first there was an object. Then he had a property and it was necessary to refer to it as an object.property. Everything would be fine, but sometimes it was necessary to get not the value of the property, but a pointer to it, so the entry object appeared. property This entry seemed ugly to many and was replaced with an object-> property. Those. in C ++, "->" is equivalent to ". ", and the final version apparently migrated to php.

PS: somehow, but maybe I'm a bit mistaken.