top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Operator for functions in PHP

+1 vote
28 views

What is the "->" operator for functions called?

At the bottom of PHP: Operators - Manual (http://php.net/manual/en/language.operators.php) is the note:

"The -> operator, not listed above, is called "object operator" (T_OBJECT_OPERATOR)."

It has been down-voted 81 times. Is that because the operator is not called the "object operator"? Or is it because the note says that the operator is not listed?

I apologize if my criticism is not appropriate, but the operator is not properly documented. The "->" operator should be listed among the other PHP operators and there should be documentation of it.

The C++ standard calls the "." and "->" operators the "dot" and "arrow" operators, correspondingly. For example, see "5.2.4 Pseudo destructor call" in: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf
That is the latest draft of the newest C++ standard.

PHP can call its "->" operator whatever the designers decide, but there should be a definition to eliminate the confusion of different names depending on personal preference. A book I am reading calls the operator the "arrow operator". Is it called the object operator (as implied by the tag) or the arrow operator or something else?

posted Dec 19, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There is a difference between a token and an operator, I think people usually confuse the two. The -> is a parser token, indeed called the T_OBJECT_OPERATOR (not sure why that comment was downvoted).

Here is a complete list of PHP's parser tokens:
http://php.net/manual/en/tokens.php

answer Dec 19, 2016 by Gurminder
Similar Questions
+1 vote

I am working on an OOP project, and cannot decide which way to follow when I have to write a simple function.

For example, I want to write a function which generates a random string. In an OOP environtment, it is a matter of course to create a static class and a static method for that. But why? Isn't it more elegant, if I implement such a simple thing as a plain function? Not to mention that a function is more efficient than a class method.

So, in object-oriented programming, what is the best practice to implement such a simple function?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...