有没有办法检查一个类中是否存在函数? [英] Is there a way to check if a function exists within a class?
问题描述
我传递一些post数据来执行一个基于post数据的函数,以确定这是否应该执行我试图使用以下内容:
$ SP = new StoredProcedure();
$ b $ if(function_exists($ SP-> $ _ POST ['function']))
{
$ SP-> $ _ POST ['function']();
}
else
{
echo'函数不存在。';
}
不幸的是,这会传递以下错误:
注意:未定义的属性:StoredProcedure :: $ getFormList in
C:\DWASFiles\Sites\junglegym\VirtualDirectory0\site\wwwroot\ wp-content \plugins\qcore\qcore_waitress.php
on line 353 function does not exist。
I确定这个函数确实存在,而当我执行它时,没有 function_exists()
有没有办法检查一个函数是否存在于类中?
文档链接: I'm passing some post data to execute a function based on post data, to determine if this should execute I've tried to use the following: Unfortunately this passes the following error: Notice: Undefined property: StoredProcedure::$getFormList in
C:\DWASFiles\Sites\junglegym\VirtualDirectory0\site\wwwroot\wp-content\plugins\qcore\qcore_waitress.php
on line 353 function does not exist. I'm certain this function does exist, and when I execute it without the Is there a way to check if a function exists when it's inside a class? Docs Link:
http://www.php.net/method_exists 这篇关于有没有办法检查一个类中是否存在函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
http://www.php.net/method_exists
if(method_exists( $ SP,$ _POST ['function'])){
{
$ SP-> $ _ POST ['功能']();
}
else
{
echo'函数不存在。';
function_exists()
和 method_exists()
用于这些检查。首先是常规函数,其次是 OOP
函数。$SP = new StoredProcedure();
if(function_exists($SP->$_POST['function']))
{
$SP->$_POST['function']();
}
else
{
echo 'function does not exist.';
}
function_exists()
method_exists
checks for method of a class for a given object:if(method_exists($SP, $_POST['function'])) {
{
$SP->$_POST['function']();
}
else
{
echo 'function does not exist.';
}
function_exists()
and method_exists()
are for these checks. First is for regular functions and second for OOP
functions.