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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?