Calling Static Method of Class WITHOUT classname, PHP

102 Views Asked by At

Maybe it's foolish question, And I want to implement some utils functions using OOP in PHP, instead SP (Strudtured Programming), but with uses like SP.

An example:

class A {
  public static function x() {
    echo "using x method!";
  }
}

According to Static OOP, to use the x function I need to use:

A::x();

But I want to use only:

x();

How can do it? Thk

1

There are 1 best solutions below

0
qwertynl On
function x() {
   return A::x();
}

Or you can even try to do:

function x() {
    return A::__FUNCTION__();
}