Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试将带有参数的回调函数作为函数参数传递-获取;意外的callbackFunctionName,应为';(“x27”错误_Php_Callback_Anonymous Function_Declare_Callable Object - Fatal编程技术网

Php 尝试将带有参数的回调函数作为函数参数传递-获取;意外的callbackFunctionName,应为';(“x27”错误

Php 尝试将带有参数的回调函数作为函数参数传递-获取;意外的callbackFunctionName,应为';(“x27”错误,php,callback,anonymous-function,declare,callable-object,Php,Callback,Anonymous Function,Declare,Callable Object,我正在尝试使用并调用setInterval()函数。从链接的github页面: /** * Just for simplifying the Timers::setInterval method * * * @param callable | string $func * @param float $milliseconds * * @return integer */ function setInterval ($func, $milliseconds) { retur

我正在尝试使用并调用setInterval()函数。从链接的github页面:

/**
 * Just for simplifying the Timers::setInterval method
 *
 *
 * @param callable | string $func
 * @param float $milliseconds
 *
 * @return integer
 */
function setInterval ($func, $milliseconds)
{
    return Timers::setInterval($func, $milliseconds);
}
如您所见,它将函数作为第一个参数,因此我尝试向它传递一个回调函数

declare(ticks=1) {
            setInterval(function callbackFunction() use $someArrayFromOuterScope {

                    runSomeOtherFunction();
                    //Do something

            }, $someArrayFromOuterScope[0]["time"]);
}
但我得到了一个错误:

分析错误:语法错误,意外调用函数,应为“(”

所以问题是我做错了什么,我该如何纠正它?

试试这个

    function setInterval ($func, $milliseconds)
    {
        return Timers::setInterval($func, $milliseconds);
    }
    declare(ticks=1) {
        setInterval(function($someArrayFromOuterScope) {

                runSomeOtherFunction();
                //Do something

        }, $someArrayFromOuterScope[0]["time"]);
    }

任何匿名函数都不应该有名称。这是您在此处的语法错误。“试试这个”并不是一个好的答案。您应该解释这是如何以及为什么解决了它们的问题。我建议您阅读,“