ReflectionClass::getConstructor

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getConstructor获取类的构造函数

说明

publicReflectionClass::getConstructor(): ?ReflectionMethod

获取已反射的类的构造函数。

参数

此函数没有参数。

返回值

一个 ReflectionMethod 对象,反射了类的构造函数,或者当类不存在构造函数时返回 null

示例

示例 #1 ReflectionClass::getConstructor() 的基本用法

<?php
$class
= new ReflectionClass('ReflectionClass');
$constructor = $class->getConstructor();
var_dump($constructor);
?>

以上示例会输出:

object(ReflectionMethod)#2 (2) { ["name"]=> string(11) "__construct" ["class"]=> string(15) "ReflectionClass" }

参见

To Top