2

I have two methods in a PHP class:

    public static function sID($urlID) {
            return base_convert($urlID, 10, 62) - 239000;
    }

    public static function load($urlID) {
            if ($urlID = "" || !is_numeric($urlID)) return 0;
            $id = sID($urlID); // ERROR ON THIS LINE
    }

I am getting the error:

Fatal error: Call to undefined function sID()

I have looked around online but amazingly enough, haven't found any solution to this seemingly simple problem. Is there a syntax error or otherwise?

0

2 Answers 2

4

It's a static class method, so you have to reference it with self::.

$id = self::sID($urlID);

You can also use the class name: (here, assuming class Foo):

$id = Foo::sID($urlID);

Since you're doing this within the class itself, using self:: is probably cleaner and easier to understand.

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

Comments

1

That's because you haven't declared a sID() function, you declared a static method. Which can be called with className::sID() (or self::sID() from inside the class itself).

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.