php中的is_callable()函数中的两个参数是什么?

php中的is_callable()函数中的两个参数是什么?,php,callable,Php,Callable,我是php新手,有人能告诉我最后两个参数在php的is_callable()函数中做了什么吗 在以下示例中,它返回与true和false相同的结果 function hello(){ return "Hello"; } $x = 'hello'; echo is_callable($x,false); function hello(){ return "Hello"; } $x = 'hello'; echo is_callable($x,true); 首先使用false

我是php新手,有人能告诉我最后两个参数在php的is_callable()函数中做了什么吗

在以下示例中,它返回与truefalse相同的结果

function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,false);
function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,true);
首先使用false

function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,false);
function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,true);
返回真值

现在使用true

function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,false);
function hello(){
    return "Hello";
}

$x = 'hello';
echo is_callable($x,true);
返回true

最后两个参数在该函数中的基本用途

可调用(帕龙、第二方、第三方)


我在php.net上读到过这方面的内容,但没有理解。有人能告诉我们这个函数中使用的最后两个参数是什么吗?

当第二个参数为
true
时,它不会检查第一个参数是否实际命名了一个现有函数,只检查它是否具有用于尝试调用函数的适当语法。这意味着它要么是一个字符串,要么是一个数组,其第一个元素是对象,第二个元素是字符串

例如:

is_callable('hellox', false);
返回
FALSE
,因为没有
hellox()
函数,但是:

is_callable('hellox', true);
返回
TRUE
,因为它可能是函数名

echo '<pre>';
print_r(
        ["is_callable(null, true)" => [(int)is_callable(null, true), "because null can't store callable name"],
        "is_callable(7,    true)"  =>  [(int)is_callable(7,    true), "because integer can't store callable name"],
        "is_callable('so', true)"  => [(int)is_callable('so', true), "because callable name can be saved in string"],

         "is_callable('so', false)"  => [(int)is_callable('so', false), "because such callable doesn't exists in code"],
         "is_callable('is_callable', false)"  => [(int)is_callable('is_callable', false), "because such callable exists and can be executed"],
        ]
        );
echo '</pre>';
但是

返回
FALSE
,因为数字不能用作函数。

echo';
echo '<pre>';
print_r(
        ["is_callable(null, true)" => [(int)is_callable(null, true), "because null can't store callable name"],
        "is_callable(7,    true)"  =>  [(int)is_callable(7,    true), "because integer can't store callable name"],
        "is_callable('so', true)"  => [(int)is_callable('so', true), "because callable name can be saved in string"],

         "is_callable('so', false)"  => [(int)is_callable('so', false), "because such callable doesn't exists in code"],
         "is_callable('is_callable', false)"  => [(int)is_callable('is_callable', false), "because such callable exists and can be executed"],
        ]
        );
echo '</pre>';
打印( [“is_callable(null,true)”=>[(int)is_callable(null,true),“因为null不能存储可调用的名称”], “is_callable(7,true)”=>[(int)is_callable(7,true),“因为integer无法存储可调用名称”], “is_callable('so',true)”=>[(int)is_callable('so',true),“因为可调用名称可以保存在字符串中”], “is_callable('so',false)”=>[(int)is_callable('so',false),“因为代码中不存在这样的可调用项”], “is_callable('is_callable',false)”=>[(int)is_callable('is_callable',false),“因为这样的可调用存在并且可以执行”], ] ); 回声';
所以简而言之,parameter
$syntax\u only=true
只是进行类型检查——检查可调用名称是否可以存储在输入变量中。而
false
-另外检查代码中是否确实存在这样的可调用项,并且是否可以执行