0
<?hh //strict 

foreach ($list as $id) {
    $items = new DestinationsByCountry($id);
    $remapped = $items->byKey('destination_id')->map($stringed ==> (int) $stringed);
    $this->ids->addAll($remapped);
}

foreach ($list as $id) {
    $this->ids->addAll(
        // ******* error line below *******
        new DestinationsByCountry($id)
            ->byKey('destination_id')
            ->map($stringed ==> (int) $stringed)
    );
}

两者都适用于类型检查器,但第二个导致致命错误

致命错误:语法错误,意外的 T_OBJECT_OPERATOR,期待 ')'

4

1 回答 1

1

正如上面的评论所指出的,你需要(new DestinationsByCountry($id))在 PHP 和 Hack 语法中加上括号。

类型检查器不抱怨的原因是它没有在 toplevel 对代码进行类型检查。如果这是在函数或方法中,我希望类型检查器会发现错误。如果此代码实际上在函数或方法中,请在 GitHub 上提交问题

于 2016-02-20T18:40:45.413 回答