0

I would like to use a function from inside my class in another function. I have tried just calling it but it does not seem to work. Here is what I am doing:

class dog {
    public function info($param) {
        //Do stuff here
    }
    public function call($param2) {
        //Call the info function here
        info($param2);
        //That does not seem to work though, it says info is undefined.
    }
}

So basically my question is how do I call a function from another in a class. Thank You, I am VERY new to classes! :D

3

1 Answer 1

1

In PHP you always need to use $this-> to call a class method (or any attribute). In your case the code is:

public function call($param2) {
        //Call the info function here
        $this->info($param2);
        //That does not seem to work though, it says info is undefined.
}

Please note that If you declare your method as static, then you will have to use either self:: or static::.

This is a basic PHP OOP syntax, for more information read the doc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.