美文网首页
Hack 学习笔记

Hack 学习笔记

作者: 尚无花名 | 来源:发表于2019-07-21 06:35 被阅读0次

docker run --tty --interactive -v /Users/baozhenchen/Documents/coding/hack:/mnt/mydata hhvm/hhvm:latest /bin/bash -l

hhvm fib.php 10

Hack Uses __EntryPoint as entry point, does not need to be a main function
<<__EntryPoint>>

<?hh // strict 如果是.php后缀的文件可以用这个开头
如果是hack后缀的文件,直接用 #!/usr/bin/env hhvm 就好了,不需要 <?hh //strict

Namespace

和Java不同的是,Hack里面有namespace的概念。有些函数定义在任命 namespace之外,比如sqrt, printf,这时用/sqrt, /printf来表示。 常用到的有HH, PHP, php
echo("Current namespace is ".NAMESPACE . "\n");
NS1\Sub不依赖于NS1\

echo, print, printf 比较

经常可以看到这三个东西,有什么区别呢
还有一个东西叫var_dump
echo不能输出一个array, 但是echo可以输出一个class如果这个class有__toString method的话.

定义一个项目

需要写一个hh_autoload.json文件做为一个configuration file.
然后用vendor/bin/hh-autoload 来生成和执行这个map

测试

<<DataProvider('provideSquaresExamples')>>

声明

hack可以有如下9种声明
alias declaration, class, enum, function, inclusion directive, interface, namespace, trait, use

变量的命名

__开始的是reserved by Hack language
_ placeholder variables 意思就是这个变量咱不用 常量用大写字母, const int MAX_VALUE = 100; 不需要符号
常见的context-dependent的constants有CLASS, DIR, FILE,
FUNCTION, LINE, METHOD, NAMESPACE, TRAIT

$this 指当前的object,它的类型是this

Literals

bool: true, false
integer: 10, 0b101010, 0xAf, 0XAF
floating point literals: 123.456 + 0.6E27 + 2.34e-3
INF, NAN
string literals:
单引号的string 不支持\n这种
双引号的string 支持\n这种, 还支持这种$x

heredoc string
nowdoc string
null

运算符

> 算好之后存在$$里
<=>
==>

hh推荐使用vec, dict, keyset, 很反感php里面的array 和[ ]

Supertype

num是int和float的supertype
arraykey, 的subtypes是int 和string
?int

相关文章

网友评论

      本文标题:Hack 学习笔记

      本文链接:https://www.haomeiwen.com/subject/wwnklctx.html