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?
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.
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).