0 2 Votes

PHP: What is the meaning of the arrow -> in PHP?

Question by Guest | 07/07/2015 at 18:21

I have already worked with several programming languages, but I am quite new with PHP. Nevertheless, I was able to find my way in the PHP syntax quite quickly, because many things are similar to other languages.

However, not all. For example, in some code examples, I was confronted with an arrow, written as a hyphen character and a greater-than-sign (->). I have never seen something like that in other programming languages.

Is someone able to explain the meaning of this arrow in PHP to me?

ReplyPositiveNegative

NetLabel

Show Profile | Message
Avatar
1Best Answer
1 Vote

With the arrow, you can access methods, functions and properties of classes in PHP. In other programming languages, often the period is used for this.

Here is a small example for PHP:

$obj = new MyClass();
$str = $obj->getString();
$int = $obj->getInt();
$obj->doSomething();

We are creating a new object of the class MyClass and afterwards we are accessing the functions getString() and getInt() in order to store the results in the variables $str and $int. After that, we are calling the method doSomething.

In another programming language, the same example might look something like that:

obj = MyClass.Create();
str = obj.getString();
int = obj.getInt();
obj.doSomething();

Basically, it is the same, only with a dot instead of the arrow.
07/07/2015 at 19:10

ReplyPositive Negative
Reply

Related Topics

Meaning of AFAIK?
Question | 1 Answer
Meaning of BTW or OBTW?
Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.