Hacklang教程 - 扩展类中的这种类型

Ati*_*ris 2 php facebook hacklang

什么是黑客教程练习16的正确答案?
链接到教程:Hacklang教程

我的修改后的代码(未标记为解决方案):

<?hh
// The type 'this' always points to the most derived type
class MyBaseClass {
  protected int $count = 0;

  public function add1(): this {
    $this->count += 1;
    return $this;
  }
}

class MyDerivedClass extends MyBaseClass {
  public function print_count(): void { echo $this->count; }
}

function test(): void {
  $x = new MyDerivedClass();
  $x->add1()->print_count();
}
Run Code Online (Sandbox Code Playgroud)

我换过MyBaseClass通过this,但仍然没有被标记为正确的(绿色文本与Exercice号)..什么是正确的答案?

Jos*_*man 5

我是Hack的工程师.我很确定在本教程的练习中,我们的完成检测逻辑中存在一个错误.你的代码对我来说是正确的 - 根据我的意见,将返回类型更改this为你应该做的所有事情.我会跟进并修复此错误.对于那个很抱歉!