gpt4 book ai didi

PHP方法存在于类中而不创建对象

转载 作者:行者123 更新时间:2023-12-02 00:59:52 26 4
gpt4 key购买 nike

在输入数据中,我有文件名、类名和方法名。我需要在不构造的情况下检查此类中的文件存在性(完成)类存在性(完成)和方法存在性。可能吗?

最佳答案

尝试使用反射:

$method = null;

try{
$class = new ReflectionClass('Your_Class');
$method = $class->getMethod('Your_Method');
}
catch(Exception $e){
echo $e->getMessage();
}

if($method != null){
// your code here;
}

关于PHP方法存在于类中而不创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29901634/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com