language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/10-comments-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/10-comments.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ // A single line comment. /* A multi line comment. * */ /** * A doc comment starts with two asterisks. * * It summarises the purpose of a definition, such as a * function, class or method. */ function foo(): void {}
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/13-names-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/13-names.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class Data { const int MAX_VALUE = 100; private int $value = 0; /* ... */ } interface ICollection { /* ... */ } enum Position: int { Top = 0; Bottom = 1; Left = 2; Right = 3; Center = 4; } function compute(int $val): void { $count = $val + 1; /* ... */ }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $val = true; if ($val === false) { // ... } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-02.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $count = 10; // decimal 10 0b101010 >> 4; // binary 101010 and decimal 4 0XAf << 012; // hexadecimal Af and octal 12 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-03.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $amount = 394_493_392; // completely equivalent to 394493392 $address = 0x49AD_DF30; $permission = 012_212_001; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-04.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 123.456 + 0.6E27 + 2.34e-3; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-05.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 123_456.49_30e-30_30; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-06.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 'Welcome to Hack!'; 'Can embed a single quote (\') and a backslash (\\) like this'; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-07.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { "Welcome to Hack!"; "Can embed a double quote (\") and a backslash (\\) like this"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-08.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { "First line 1\nSecond line 2\n\nFourth line\n"; "Can embed a double quote (\") and a backslash (\\) like this"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-09.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class C { public int $p1 = 2; } <<__EntryPoint>> function main(): void { $x = 123; echo ">\$x.$x"."<\n"; $myC = new C(); echo "\$myC->p1 = >$myC->p1<\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-10.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function has_default_arg(num $arg, ?num $base = null): void {}
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/19-literals-11.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/19-literals.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ type IdSet = shape('id' => ?string, 'url' => ?string, 'count' => int); function get_IdSet(): IdSet { return shape('id' => null, 'url' => null, 'count' => 0); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/28-constants-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/28-constants.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ const int MAX_COUNT = 123; class C { const float MAX_HEIGHT = 10.5; const float UPPER_LIMIT = C::MAX_HEIGHT; } <<__EntryPoint>> function main(): void { echo "MAX_COUNT = ".MAX_COUNT."\n"; echo "MAX_HEIGHT = ".C::MAX_HEIGHT."\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/31-variables-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/31-variables.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function do_it(bool $p1): void { $count = 10; // ... if ($p1) { $message = "Can't open file."; // ... } // ... } function call_it(): void { do_it(true); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/31-variables-02.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/31-variables.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function f(): void { $lv = 1; echo "\$lv = $lv\n"; ++$lv; } <<__EntryPoint>> function main(): void { for ($i = 1; $i <= 3; ++$i) f(); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/31-variables-03.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/31-variables.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $colors1 = vec["green", "yellow"]; // create a vec of two elements $colors1[] = "blue"; // add element 2 with value "blue" $colors2 = dict[]; // create an empty dict $colors2[4] = "black"; // create element 4 with value "black" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/37-namespaces-01.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/37-namespaces.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ namespace NS1; // ... // __NAMESPACE__ is "NS1" namespace NS3\Sub1; // ... // __NAMESPACE__ is "NS3\Sub1"
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/37-namespaces-02.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/37-namespaces.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ namespace NS1 { // __NAMESPACE__ is "NS1" } namespace { // __NAMESPACE__ is "" } namespace NS3\Sub1 { // __NAMESPACE__ is "NS3\Sub1" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/02-source-code-fundamentals/37-namespaces-03.hack
// @generated by hh_manual from manual/hack/02-source-code-fundamentals/37-namespaces.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ namespace NS1 { const int CON1 = 100; function f(): void { echo "In ".__FUNCTION__."\n"; } class C { const int C_CON = 200; public function f(): void { echo "In ".__NAMESPACE__."...".__METHOD__."\n"; } } interface I { const int I_CON = 300; } trait T { public function f(): void { echo "In ".__TRAIT__."...".__NAMESPACE__."...".__METHOD__."\n"; } } } namespace NS2 { use type NS1\{C, I, T}; class D extends C implements I { use T; } function f(): void { $d = new D(); echo "CON1 = ".\NS1\CON1."\n"; \NS1\f(); } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/09-echo-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/09-echo.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $v1 = true; $v2 = 123.45; echo '>>'.$v1.'|'.$v2."<<\n"; // outputs ">>1|123.45<<" $v3 = "abc{$v2}xyz"; echo "$v3\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/10-exit-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/10-exit.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { exit ("Closing down\n"); exit (1); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $tuple = tuple('one', 'two', 'three'); list($one, $two, $three) = $tuple; echo "1 -> {$one}, 2 -> {$two}, 3 -> {$three}\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ <<__EntryPoint>> function main(): void { $tuple = tuple('string', 1, false); list($string, $int, $bool) = $tuple; takes_string($string); takes_int($int); takes_bool($bool); echo 'The typechecker understands the types of list().'; } function takes_string(string $_): void {} function takes_int(int $_): void {} function takes_bool(bool $_): void {}
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $tuple = tuple('a', 'b', 'c', 1, 2, 3); list($_, $b, $c, $_, $two, $_) = $tuple; echo "b -> {$b}, c -> {$c}, two -> {$two}\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $a = tuple(1, 2); // BAD, since $a is used on the right and on the left! list($a, $b) = $a; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $tuple = tuple('top level', tuple('inner', 'nested')); list($top_level, list($inner, $nested)) = $tuple; echo "top level -> {$top_level}, inner -> {$inner}, nested -> {$nested}\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/13-list-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/13-list.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $vec_of_tuples = vec[ tuple('A', 'B', 'C'), tuple('a', 'b', 'c'), tuple('X', 'Y', 'Z'), ]; foreach ($vec_of_tuples as list($first, $second, $third)) { echo "{$first} {$second} {$third}\n"; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/21-new-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/21-new.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class Point { private static int $pointCount = 0; // static property with initializer private float $x; // instance property private float $y; // instance property public function __construct(num $x = 0, num $y = 0) { // instance method $this->x = (float)$x; // access instance property $this->y = (float)$y; // access instance property ++Point::$pointCount; // include new Point in Point count } } function main(): void { $p1 = new Point(); // create Point(0.0, 0.0) $p2 = new Point(5, 6.7); // create Point(5.0, 6.7) }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/21-new-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/21-new.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ final class C {} function f(classname<C> $clsname): void { $w = new $clsname(); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/25-subscript-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/25-subscript.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $text = "Hello"; $e = $text[4]; // designates the element with key 4 value "o" $text[1] = "?"; // changes the element with key 1 from "e" to "?" $v = vec[10, 25, -6]; $e = $v[1]; // designates the element with key 1 value 25 $v[2] = 44; // changes the element with key 2 from -6 to 44 $d = dict["red" => 4, "white" =>12, "blue" => 3]; $e = $d["white"]; // designates the element with key "white" value 12 $d["red"] = 9; // changes the element with key "red" from 4 to 9 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/25-subscript-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/25-subscript.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $v = vec[10, 25, -6]; $v[] = 99; // creates new element with key 3, value 99 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/29-member-selection-intbox.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/29-member-selection.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class IntBox { private int $x; public function __construct(int $x) { $this->x = $x; // Assigning to property. } public function getX(): int { return $this->x; // Accessing property. } } <<__EntryPoint>> function main(): void { $ib = new IntBox(42); $x = $ib->getX(); // Calling instance method. } function my_example(?IntBox $ib): ?int { return $ib?->getX(); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ enum ControlStatus: int { Stopped = 0; Stopping = 1; Starting = 2; Started = 3; } function main(ControlStatus $p1): void { switch ($p1) { case ControlStatus::Stopped: // ... break; case ControlStatus::Stopping: // ... break; default: break; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ final class MathLibrary { const PI = 3.1415926; public static function sin(float $val): float { return 0.0; // stub } } function use_it(): void { $radius = 3.4; $area = MathLibrary::PI * $radius * $radius; $v = MathLibrary::sin(2.34); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class Point { private static int $pointCount = 0; public static function getPointCount(): int { return self::$pointCount; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class MyRangeException extends Exception { public function __construct(string $message) { parent::__construct('MyRangeException: '.$message); } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class Base { public function b(): void { static::f(); // calls the most appropriate f() } public static function f(): void { //... } } class Derived extends Base { public static function f(): void { // ... } } function demo(): void { $b1 = new Base(); $b1->b(); // as $b1 is an instance of Base, Base::b() calls Base::f() $d1 = new Derived(); $d1->b(); // as $d1 is an instance of Derived, Base::b() calls Derived::f() }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/33-scope-resolution-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/33-scope-resolution.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ namespace NS_cn; class C1 { // ... } class C2 { public static classname<C1> $p1 = C1::class; public static function f(?classname<C1> $p): void {} public static vec<classname<C1>> $p2 = vec[C1::class]; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/37-incrementing-and-decrementing-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/37-incrementing-and-decrementing.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { for ($i = 1; $i <= 10; $i++) { // ... } }
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/37-incrementing-and-decrementing-02.hack_error
// @generated by hh_manual from manual/hack/03-expressions-and-operators/37-incrementing-and-decrementing.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $x = 0; $y = $x++; // Parse error. }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/37-incrementing-and-decrementing-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/37-incrementing-and-decrementing.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $x = 0; $y = $x + 1; $x++; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/47-error-control-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/47-error-control.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $infile = @fopen("NoSuchFile.txt", 'r'); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/49-casting-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/49-casting.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { (float)1; // 1.0 (int)3.14; // 3, rounds towards zero (bool)0; // false (string)false; // "" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 is int; // true 'foo' is int; // false 1 is num; // true 1.5 is num; // true 'foo' is num; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ enum MyEnum: int { FOO = 1; } function demo(): void { 1 is MyEnum; // true 42 is MyEnum; // false 'foo' is MyEnum; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $x = tuple(1, 2.0, null); $x is (int, float, ?bool); // true $y = shape('foo' => 1); $y is shape('foo' => int); // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ type myint = int; function demo(): void { 1 is myint; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 as int; // 1 'foo' as int; // TypeAssertionException }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/52-type-assertions-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/52-type-assertions.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 ?as int; // 1 'foo' ?as int; // null }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { -10 + 100; // int with value 90 100 + -3.4e2; // float with value -240 9.5 + 23.444; // float with value 32.944 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { -10 - 100; // int with value -110 100 - -3.4e2; // float with value 440 9.5 - 23.444; // float with value -13.944 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { -10 * 100; // int result with value -1000 100 * -3.4e10; // float result with value -3400000000000.0 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 300 / 100; // int result with value 3 100 / 123; // float result with value 0.8130081300813 12.34 / 2.3; // float result with value 5.3652173913043 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 5 % 2; // int result with value 1 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 2 ** 3; // int with value 8 2 ** 3.0; // float with value 8.0 2.0 ** 3.0; // float with value 8.0 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-07.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $v = +10; $v = 10; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/58-arithmetic-08.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/58-arithmetic.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $v = 10; $x = -$v; // $x has value -10 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/69-string-concatenation-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/69-string-concatenation.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { "foo"."bar"; // "foobar" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/69-string-concatenation-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/69-string-concatenation.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { -10 . NAN; // string result with value "-10NAN" INF . "2e+5"; // string result with value "INF2e+5" true . null; // string result with value "1" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0b101111 & 0b101; // result is 0b101 $lcase_letter = 0x73; // lowercase letter 's' $ucase_letter = $lcase_letter & ~0x20; // clear the 6th bit to make uppercase letter 'S' }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0b101111 | 0b101; // result is 0b101111 $ucase_letter = 0x41; // uppercase letter 'A' $lcase_letter = $ucase_letter | 0x20; // set the 6th bit to make lowercase 'a' }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0b101111 ^ 0b101; // result is 0b101010 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0b101 << 2; // result is 0b10100 10 << 3; // result is 80 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0b1011 >> 2; // result is 0b10 100 >> 2; // result is 25 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { (1 << 63) >> 63; // result is -1 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/70-bitwise-operators-07.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/70-bitwise-operators.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $lLetter = 0x73; // lowercase letter 's' $uLetter = $lLetter & ~0b100000; // clear the 6th bit to make uppercase letter 'S' }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/75-comparisons-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/75-comparisons.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 < 2; // true 1.0 <= 1.5; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/75-comparisons-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/75-comparisons.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { "a" < "b"; // true "ab" < "b"; // true "01" < "1"; // false (1 == 1) }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/75-comparisons-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/75-comparisons.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 <=> 1; // 0; equal 1 <=> 2; // negative; 1 < 2 2 <=> 1; // positive; 2 > 1 "a" <=> "a"; // 0; same length and content "a" <=> "b"; // negative; a is lower than b in the collating sequence "b" <=> "a"; // positive; b is higher than a in the collating sequence "a" <=> "A"; // positive; lowercase a is higher than uppercase A "a" <=> "aa"; // negative; same leading part, but a is shorter than aa "aa" <=> "a"; // positive; same leading part, but aa is longer than a "aa" <=> "aa"; // 0; same length and content }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 === 2; // false 1 !== 2; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 === 1; // true vec[1, 2] === vec[1, 2]; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 0 === null; // false vec[1] === keyset[1]; // false // Tip: if you want to compare an integer with a float, // convert the integer value: (float)1 === 1.0; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { vec[1, 2] === vec[1, 2]; // true vec[1] === vec[2]; // false keyset[1, 2] === keyset[1, 2]; // true keyset[1, 2] === keyset[2, 1]; // false dict[0 => null, 1 => null] === dict[0 => null, 1 => null]; // true dict[1 => null, 0 => null] === dict[0 => null, 1 => null]; // false // Tip: Use Keyset\equal and Dict\equal if you // want to ignore order: Keyset\equal(keyset[1, 2], keyset[2, 1]); // true Dict\equal(dict[1 => null, 0 => null], dict[0 => null, 1 => null]); // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-05.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 !== 2; // true 2 !== 2; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-06.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 == 1.0; // false 0 == null; // false "" == 0; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-07.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { keyset[1, 2] == keyset[2, 1]; // true dict[1 => null, 2 => null] == dict[2 => null, 1 => null]; // true // Note that vec comparisons always care about order. vec[1, 2] == vec[2, 1]; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-08.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { 1 != 2; // true 1 != 1; // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-object.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class MyObject {} async function example_snippet_wrapper1(): Awaitable<void> { $obj = new MyObject(); // Different references aren't equal. $obj === new MyObject(); // false // The same reference is equal. $obj === $obj; // true }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/77-equality-wrapper.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/77-equality.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ class MyWrapper { public function __construct(private mixed $m) {} } async function example_snippet_wrapper1(): Awaitable<void> { new MyWrapper(1) == new MyWrapper(1); // true new MyWrapper(1) == new MyWrapper(2); // false }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/91-coalesce-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/91-coalesce.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $nully = null; $nonnull = 'a string'; \print_r(vec[ $nully ?? 10, // 10 as $nully is `null` $nonnull ?? 10, // 'a string' as $nonnull is `nonnull` ]); $arr = dict['black' => 10, 'white' => null]; \print_r(vec[ $arr['black'] ?? -100, // 10 as $arr['black'] is defined and not null $arr['white'] ?? -200, // -200 as $arr['white'] is null $arr['green'] ?? -300, // -300 as $arr['green'] is not defined ]); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/91-coalesce-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/91-coalesce.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $arr = dict['black' => 10, 'white' => null]; \print_r(vec[ idx($arr, 'black', -100), // 10 idx($arr, 'white', -200), // null idx($arr, 'green', -300), // -300 idx($arr, 'green'), // null ]); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/91-coalesce-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/91-coalesce.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function get_counts_by_value(Traversable<string> $values): dict<string, int> { $counts_by_value = dict[]; foreach ($values as $value) { $counts_by_value[$value] ??= 0; ++$counts_by_value[$value]; } return $counts_by_value; } function get_people_by_age( KeyedTraversable<string, int> $ages_by_name, ): dict<int, vec<string>> { $people_by_age = dict[]; foreach ($ages_by_name as $name => $age) { $people_by_age[$age] ??= vec[]; $people_by_age[$age][] = $name; } return $people_by_age; } <<__EntryPoint>> function main(): void { $values = vec['foo', 'bar', 'foo', 'baz', 'bar', 'foo']; \print_r(get_counts_by_value($values)); $people = dict[ 'Arthur' => 35, 'Ford' => 110, 'Trillian' => 35, 'Zaphod' => 120, ]; \print_r( get_people_by_age($people) |> Dict\map($$, $names ==> Str\join($names, ', ')) ); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/93-pipe-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/93-pipe.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $x = vec[2,1,3] |> Vec\map($$, $a ==> $a * $a) // $$ with value vec[2,1,3] |> Vec\sort($$); // $$ with value vec[4,1,9] }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/93-pipe-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/93-pipe.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { Vec\sort(Vec\map(vec[2, 1, 3], $a ==> $a * $a)); // Evaluates to vec[1,4,9] }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/97-assignment-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/97-assignment.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $a = 10; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/97-assignment-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/97-assignment.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $v = vec[1, 2, 3]; $v[0] = 42; // $v is now vec[42, 2, 3] $v = dict[0 => 10, 1 => 20, 2 => 30]; $v[1] = 22; // change the value of the element with key 1 $v[-10] = 19; // insert a new element with key -10 }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/97-assignment-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/97-assignment.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $d = dict['x' => 1]; $d['y'] = 42; // $d is now dict['x' => 1, 'y' => 42] }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/97-assignment-04.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/97-assignment.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $s = "ab"; $s[0] = "x"; // in bounds $s[3] = "y"; // $s is now "xb y" }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/98-yield-01.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/98-yield.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function series( int $start, int $end, int $incr = 1, ): \Generator<int, int, void> { for ($i = $start; $i <= $end; $i += $incr) { yield $i; } } <<__EntryPoint>> function main(): void { foreach (series(5, 15, 2) as $key => $val) { echo "key: $key, value: $val\n"; } echo "-----------------\n"; foreach (series(25, 20, 3) as $key => $val) { echo "key: $key, value: $val\n"; } echo "-----------------\n"; }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/98-yield-02.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/98-yield.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function squares( int $start, int $end, string $keyPrefix = "", ): Generator<string, int, void> { for ($i = $start; $i <= $end; ++$i) { yield $keyPrefix.$i => $i * $i; // specify a key/value pair } } <<__EntryPoint>> function main(): void { foreach (squares(-2, 3, "X") as $key => $val) { echo "key: $key, value: $val\n"; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/03-expressions-and-operators/98-yield-03.hack
// @generated by hh_manual from manual/hack/03-expressions-and-operators/98-yield.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function getTextFileLines(string $filename): Generator<int, string, void> { $infile = fopen($filename, 'r'); if ($infile === false) { // handle file-open failure } try { while (true) { $textLine = fgets($infile); if ($textLine === false) { break; } $textLine = rtrim($textLine, "\r\n"); // strip off line terminator yield $textLine; } } finally { fclose($infile); } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/02-break-and-continue-01.hack
// @generated by hh_manual from manual/hack/04-statements/02-break-and-continue.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { for ($i = 1; $i <= 10; ++$i) { if (($i % 2) === 0) { continue; } echo "$i is odd\n"; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/03-do-01.hack
// @generated by hh_manual from manual/hack/04-statements/03-do.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $i = 1; do { echo "$i\t".($i * $i)."\n"; // output a table of squares ++$i; } while ($i <= 10); }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/04-for-01.hack
// @generated by hh_manual from manual/hack/04-statements/04-for.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { for ($i = 1; $i <= 5; ++$i) { echo "$i\t".($i * $i)."\n"; // output a table of squares } $i = 1; for (; $i <= 5; ) { echo "$i\t".($i * $i)."\n"; // output a table of squares ++$i; } $i = 1; for (; ; ) { if ($i > 5) break; echo "$i\t".($i * $i)."\n"; // output a table of squares ++$i; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/05-foreach-01.hack
// @generated by hh_manual from manual/hack/04-statements/05-foreach.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $colors = vec["red", "white", "blue"]; foreach ($colors as $color) { // ... } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/05-foreach-02.hack
// @generated by hh_manual from manual/hack/04-statements/05-foreach.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $colors = vec["red", "white", "blue"]; foreach ($colors as $key => $color) { // ... } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/05-foreach-03.hack
// @generated by hh_manual from manual/hack/04-statements/05-foreach.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $a = dict['a' => 10, 'f' => 30]; foreach ($a as $key => $_) { // 10 and 30 are ignored // ... } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/06-if-01.hack
// @generated by hh_manual from manual/hack/04-statements/06-if.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ async function example_snippet_wrapper(): Awaitable<void> { $count = 11; if ($count < 10) { echo "small"; } else if ($count < 20) { echo "medium"; } else { echo "large"; } }
Hack
hhvm/hphp/hack/test/extracted_from_manual/04-statements/07-return-01.hack
// @generated by hh_manual from manual/hack/04-statements/07-return.md // @codegen-command : buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract fbcode/hphp/hack/manual/hack/ function average_float(float $p1, float $p2): float { return ($p1 + $p2) / 2.0; } type IdSet = shape('id' => ?string, 'url' => ?string, 'count' => int); function get_IdSet(): IdSet { return shape('id' => null, 'url' => null, 'count' => 0); } class Point { private float $x; private float $y; public function __construct(num $x = 0, num $y = 0) { $this->x = (float)$x; // sets private property $x $this->y = (float)$y; // sets private property $y } // no return statement public function move(num $x = 0, num $y = 0): void { $this->x = (float)$x; // sets private property $x $this->y = (float)$y; // sets private property $y return; // return nothing } // ... }