Jump to content

The arrow operator


Guest clv

Recommended Posts

This is no doubt one of those questions that is so basic, no one bothers to explain it in the books.

 

When reading something like $object->property or $stefan->name; do we read the arrow operator like a possessive apostrophe?

i.e. Stefan's name (the name of Stefan)?

Link to comment
Share on other sites

When reading something like $object->property or $stefan->name; do we read the arrow operator like a possessive apostrophe?

i.e. Stefan's name (the name of Stefan)?

I'm not sure there are any specific rules on this, but I suppose you could do that, since you are talking about a variable or function that is associated with a particular object.

Link to comment
Share on other sites

It's like in Java Integer.parseNext();

but in PHP we use the arrow so we would do Integer->parseNext();

So what you do is specify the object type, in this case Integer and call the function in that object by the refference -> to call the object member parseNext().

 

So to formally wrap it up:

It's how PHP let's you reference a member of some class. If there was some class reference stored in the variable $foo and there was a member function 'noWay()' you could call it by writing '$foo->noWay()', it's the namespace separator or object access operator. you use it to reference member data of an object.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...