Jump to content

What exactly is -> for?


iarp

Recommended Posts

I've been taking a look at the coding for Wordpress and PHPBB to see if i could get any ideas, or grasp any concepts from them on how to do things with the website i'm working on. On both pieces of coding i see alot of -> but don't get exactly how they work

 

Is it like:

 

function taxes(cost, taxRate) {

$answer = etc...etc

}

 

$data -> taxes($baseCost, 1.13);

 

?

Link to comment
Share on other sites

isarp:

 

It references a value or method inside of a class. If you have never played with object oriented programming, I would not worry about trying to understand it. Object oriented programming is much more complex and confusing.

Link to comment
Share on other sites

To further that point say you had a class named dog. You could code functions within dog like say bark. So if you wanted to call bark you would use that sign example

 

class Dog {
    public function bark() {
        echo "Roof!";
    }
}

//Then to call it you would say
$dog -> bark();

 

This would echo "Roof!";

Link to comment
Share on other sites

To further that point say you had a class named dog. You could code functions within dog like say bark. So if you wanted to call bark you would use that sign example

 

class Dog {
    public function bark() {
        echo "Roof!";
    }
}

//Then to call it you would say
$dog -> bark();

 

This would echo "Roof!";

 

Makes sense, thank you. That first link to the manual just confused the crap outta me 0.o

Link to comment
Share on other sites

I actually read through it to compile the example for you. I have used it in c++ before for pointers i think but that was while ago. The cool thing about classes is you can create new ones on the fly. So if you were making like a pet program to train them you could copy the dog class on the fly and assign it an instance so it can hold variables like health, and weight, and be separate from the other instances of the dog classes. Thats the cool thing about oop (object orientated programming).

Link to comment
Share on other sites

Well yes it can, but it can assign values to variables within classes as well. Consider it sorta like " 's ". So dog -> bark() would be like saying dog's bark function. Or dog -> health = 20; Would be like saying Dog's health equals 20. So it is really just to access code more or less within an object or in this case a class. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.