hack屬性:介紹

2018-12-01 11:39 更新

屬性是元數(shù)據(jù)的任何一個保持器可反射一段代碼。這包括函數(shù),類,接口,特性等

除了一些特殊的屬性,屬性是一個純粹的句法實體。他們利用工具來完成任務(wù)。例如,您可以擁有基于文檔的屬性,其內(nèi)容通過反射提取。

<?hh

namespace Hack\UserDocumentation\Attributes\Intro\Examples\Simple;

<<ClassOwner("Joel Marcey"), Description("This class does nothing")>>
class Simple {}

function get_attributes(): void {
  $rc = new \ReflectionClass(
    "Hack\UserDocumentation\Attributes\Intro\Examples\Simple\Simple"
  );
  var_dump($rc->getAttributes()["Description"]);
}

get_attributes();

Output

array(1) {
  [0]=>
  string(23) "This class does nothing"
}

特殊屬性

一些屬性對Hack類型檢查器和HHVM都有特殊的含義。這里是最常見和有用的:

還有一些不太常見的特殊屬性。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號