-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update guides/hack from HHVM repository
- Loading branch information
1 parent
2ca5842
commit bd83afc
Showing
2 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
```yamlmeta | ||
{ | ||
"fbonly messages": [ | ||
"This type is under migration, and is allowed to flow to the [classname type](/hack/built-in-types/classname) for existing string use cases. There is [an internal wiki](https://www.internalfb.com/intern/wiki/Hack_Foundation/classnameC_vs._classC/) describing the type separation." | ||
] | ||
} | ||
``` | ||
|
||
Hack supports passing references to classes for use in instatiation and static | ||
member access. | ||
|
||
```Hack no-extract | ||
<<__ConsistentConstruct>> | ||
class Employee { | ||
public static function getKind(): int { return 4; }; | ||
} | ||
function f(class<Employee> $cls): void { | ||
$w = new $cls(); // create an object of $cls | ||
$i = $cls::getKind(); | ||
} | ||
``` | ||
|
||
Function `f` can be called with a reference to the class `Employee` or any of | ||
its subclasses using `::class` literals (`SomeClassName::class`). | ||
|
||
```Hack no-extract | ||
class Intern extends Employee { | ||
// ... | ||
} | ||
function demo(): void { | ||
f(Employee::class); // will call: new Employee(); | ||
f(Intern::class); // will call: new Intern(); | ||
f(Vector::class); // typechecker error! | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters