ReflectionClass::getConstructor

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getConstructor獲取類的構(gòu)造函數(shù)

說明

public ReflectionClass::getConstructor(): ReflectionMethod

獲取已反射的類的構(gòu)造函數(shù)。

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

一個 ReflectionMethod 對象,反射了類的構(gòu)造函數(shù),或者當(dāng)類不存在構(gòu)造函數(shù)時返回 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"
}

參見