dtx9931 2014-11-23 18:56
浏览 22
已采纳

PHP Dice IoC - 解析错误:语法错误,意外'。'?

I am trying to use Dice for my dependency injection.

When I run the code below (from Dice doc),

include 'dice.php';

class A {
    private $b;

    public function __construct(B $b) {
        $this->b = $b;
    }
}

class B {
    private $c,$d;

    public function __construct(C $c, D $d) {
        $this->c = $c;
        $this->d = $d;
    }
}

class C {

}

class D {
    private $e;

    public function __construct(E $e) {
        $this->e = $e;
    }
}

class E {

}


$dice = new \Dice\Dice;
$a = $dice->create('A');
print_r($a);

I get this error,

Parse error: syntax error, unexpected '.' in C:...\dice.php on line 38

If you open dice.php, this is the line the error message refers to,

else $object = $params ? new $class->name(...$params($args)) : new $class->name;

I does look strange to me - ...$params what is that??

Any ideas?

  • 写回答

2条回答 默认 最新

  • duanjiao7440 2014-11-23 19:09
    关注

    The vararg/splat operator (...) is a new feature introduced in PHP 5.6. Strange that a popular library relies on such obscure syntax but it seems you have to upgrade for your code to successfully run.

    PHP 5.6 New features

    PHP 5.6 and the Splat Operator

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器