Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.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
将PHP5.6级降级为5.5级_Php_Php 5.5_Php 5.6 - Fatal编程技术网

将PHP5.6级降级为5.5级

将PHP5.6级降级为5.5级,php,php-5.5,php-5.6,Php,Php 5.5,Php 5.6,我创建了一个类来堆叠对象层和闭包,但我的服务器还没有在PHP5.6上运行。我想知道如何转换…$parameters,因为我无法通过使用call\u user\u func\u array()替换所有内容来修复它,然后buildCoreClosure()方法将抛出错误,例如,因为闭包不是数组 class Stack { /** * Method to call on the decoracted class. * * @var string */

我创建了一个类来堆叠对象层和闭包,但我的服务器还没有在PHP5.6上运行。我想知道如何转换
…$parameters
,因为我无法通过使用
call\u user\u func\u array()
替换所有内容来修复它,然后
buildCoreClosure()
方法将抛出错误,例如,因为闭包不是数组

class Stack
{
    /**
     * Method to call on the decoracted class.
     *
     * @var string
     */

    protected $method;

    /**
     * Container.
     */

    protected $container;

    /**
     * Middleware layers.
     *
     * @var array
     */

    protected $layers = [];

    public function __construct(Container $container = null, $method = null)
    {
        $this->container = $container ?: new Container;
        $this->method = $method ?: 'handle';
    }

    public function addLayer($class, $inner = true)
    {
        return $inner ? array_unshift($this->layers, $class) : array_push($this->layers, $class);
    }

    public function addInnerLayer($class)
    {
        return $this->addLayer($class);
    }

    public function addOuterLayer($class)
    {
        return $this->addLayer($class, false);
    }

    protected function buildCoreClosure($object)
    {
        return function(...$arguments) use ($object)
        {
            $callable = $object instanceof Closure ? $object : [$object, $this->method];

            return $callable(...$arguments);
        };
    }

    protected function buildLayerClosure($layer, Closure $next)
    {
        return function(...$arguments) use ($layer, $next)
        {
            return $layer->execute(...array_merge($arguments, [$next]));
        };
    }


    public function peel($object, array $parameters = [])
    {
        $next = $this->buildCoreClosure($object);

        foreach($this->layers as $layer)
        {
            $layer = $this->container->get($layer);

            $next = $this->buildLayerClosure($layer, $next);
        }

        return $next(...$parameters);
    }
}
除去

...$arguments
在每个函数的参数列表中,并将其替换为以下内容(函数的早期部分)


您可以获得相同的参数值。即使未在函数的参数列表中定义参数,参数仍将传递给func_get_args()。

修复方法是用
func_get_args()
替换
…$Arguments
。我以前在本例中使用了参数数组,以避免将它们全部列出。
$arguments = func_get_args();