我决定开始一个新项目进入hacklang,并在修复了一些问题之后我最初遇到了从php习惯过渡的问题,我遇到了以下错误:
Unbound name: str_replace
Unbound name: empty
Run Code Online (Sandbox Code Playgroud)
做一些研究我发现这是因为使用了'遗留'的php,它不是类似于typecheck,并且会出错//strict.
这很好,所有,empty()很容易取代,但str_replace()有点困难.
是否有一个等效函数可以使用//strict?或至少类似的东西.
我知道我可以使用,//decl但我觉得在我的情况下失败了目的.
是否至少有任何方法可以告诉哪些函数在hack中实现,哪些不在文档中,因为我找不到?
作为参考(虽然它与问题本身不太相关),这里是代码:
<?hh //strict
class HackMarkdown {
public function parse(string $content) : string {
if($content===null){
throw new RuntimeException('Empty Content');
}
$prepared = $this->prepare($content);
}
private function prepare(string $contentpre) : Vector<string>{
$contentpre = str_replace(array("\r\n","\r"),"\n",$contentpre);
//probably need more in here
$prepared = Vector::fromArray(explode($contentpre,"\n"));
//and here
return $prepared;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2817 次 |
| 最近记录: |