Fluffy
Fluffy

Reputation: 28342

How to check whether a method is static in PHP?

I need to know whether the method is declared as static given its name and the name of the class containing it. method_exists provides true for both static and non-static methods.

Upvotes: 8

Views: 5042

Answers (2)

Edson Medina
Edson Medina

Reputation: 10269

use ReflectionMethod::isStatic

Upvotes: 6

Nathan J.B.
Nathan J.B.

Reputation: 10315

Here's a little more clear way on how to use ReflectionMethod:

$MethodChecker = new ReflectionMethod($ClassName,$MethodName);
var_dump($MethodChecker->isStatic());

Upvotes: 16

Related Questions