42

This is probably a really simple question however Google isn't my friend today.

I have something like this but it says call to undefined function

<?php
    class myClass{
        function doSomething($str){
            //Something is done here
        }
        function doAnother($str){
            return doSomething($str);
        }
    }
?>

4 Answers 4

80

Try the following:

return $this->doSomething($str);
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use self::doSomething($str); as well
26

You can try a static call like this:

function doAnother ($str) {
    return self::doSomething($str);
}

Or if you want to make it a dynamic call, you can use $this keyword, thus calling a function of a class instance:

function doAnother ($str) {
    return $this->doSomething($str);
}

Comments

10

Try:

return $this->doSomething($str);

Have a look at this as well: http://php.net/manual/en/language.oop5.php

Comments

5

try:

return $this->doSomething(str);

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.