user2730587
user2730587

Reputation:

Calling Static Method of Class WITHOUT classname, PHP

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

Upvotes: 1

Views: 100

Answers (1)

qwertynl
qwertynl

Reputation: 3933

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

Or you can even try to do:

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

Upvotes: 2

Related Questions