class Foo { public function __construct() {} public function bar() {} } $foo = new ReflectionMethod('Foo', '__construct'); if ($foo->isConstructor()) { echo 'This method is a constructor'; } else { echo 'This method is not a constructor'; }
class Foo { public function __construct() {} public function bar() {} } $foo = new ReflectionMethod('Foo', 'bar'); if ($foo->isConstructor()) { echo 'This method is a constructor'; } else { echo 'This method is not a constructor'; }In this example, we create a new class called Foo with a constructor and another method called bar. We then create a new instance of ReflectionMethod for the bar method and use the isConstructor method to determine that it is not a constructor. Package library: ReflectionMethod is a built-in PHP class and is part of the Reflection package/library.