Common hack php functions

I decided to start a new project to get into the hacklang, and after fixing some of the problems that I initially encountered when switching from php habits, I encountered the following errors:

Unbound name: str_replace Unbound name: empty 

After doing some research, I found that this is due to the use of "legacy" php, which is not checked by typechecked, and will be an error with //strict .

That's fine and all, empty() was easy enough to replace, however str_replace() bit more complicated.

Is there an equivalent function that will work with //strict? Or at least something like that.

I know that I can use //decl , but I feel that this defeats the goal in my case.

Is there any way to tell which functions are implemented in the hack and which are not in the documentation, since I could not find them?

For reference (although this is not too relevant for the question itself), here is the code:

 <?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; } } 
+7
hacklang
source share
1 answer

You do not need to change your code at all. You just need to tell Hack tools about all the built-in PHP functions.

The easiest way to do this is to download this folder and put it in your project. I put it in the hhi folder in the base of my project. The files there tell Hack about all the PHP built-in functions.

Most of them do not have type hints, which can lead to the fact that Hack thinks that the return type is all mixed instead of the actual return, which in most cases is correct, since, for example, str_replace can return either a string or a bool . However, it stops the "unrelated name" errors, which is the main reason for adding them.

+5
source share

All Articles