2024 年日本 PHP 研討會

ReflectionMethod::createFromMethodName

(PHP 8 >= 8.3.0)

ReflectionMethod::createFromMethodName建立新的 ReflectionMethod

說明

public static ReflectionMethod::createFromMethodName(字串 $method): static

建立新的 ReflectionMethod

參數

method

:: 分隔的類別名稱和方法名稱。

傳回值

成功時會回傳一個新的 ReflectionMethod 物件。

錯誤/例外

如果指定的 method 不存在,會拋出 ReflectionException

範例

範例 #1 ReflectionMethod::createFromMethodName() 範例

<?php

class Foo {
public function
bar() {

}
}

$methodInfo = ReflectionMethod::createFromMethodName("Foo::bar");
var_dump($methodInfo);
?>

上述範例會輸出:

object(ReflectionMethod)#1 (2) {
  ["name"]=>
  string(3) "bar"
  ["class"]=>
  string(3) "Foo"
}
新增筆記

使用者貢獻的筆記

這個頁面沒有使用者貢獻的筆記。
To Top