ReflectionClass::getConstructor

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getConstructor獲取類的構造函數

說明

public ReflectionClass::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"
}

參見