1<?php 2$foo = (int) $bar; 3$foo = (integer) $bar; 4$foo = (bool) $bar; 5$foo = (boolean) $bar; 6$foo = (float) $bar; 7$foo = (double) $bar; 8$foo = (real) $bar; 9$foo = (string) $bar; 10$foo = (array) $bar; 11$foo = (object) $bar; 12$foo = (unset) $bar; 13 14$foo = (Int) $bar; 15$foo = (INTEGER) $bar; 16$foo = (BOOL) $bar; 17$foo = (String) $bar; 18$foo = ( Array ) $bar; 19 20function foo(int $a, string $b, bool $c, array $d, Foo\Bar $e) : int {} 21function foo(Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Foo\Bar {} 22function foo(Int $a, Bar $b, BOOL $c, Array $d, Foo\Bar $e) : Bar {} 23function foo(callable $a, Callable $b, self $c, Iterable $d, iterable $e) : Float {} 24 25$foo = function (int $a, Bool $b) {}; 26$foo = function (int $a, Callable $b) :INT{}; 27$foo = function (BOOL $a, float $b) use ($foo) : INT {}; 28$foo = function (Foo $a, Foo\Bar $b) use ($foo) : \Foo\Bar {}; 29$foo = function (bool $a, callable $b) use ($foo) : Bar {}; 30 31class Testing { 32 public function TestThis(SELF $a, obJect $b, Parent $c) : VOID {} 33} 34 35function foo( 36 ?Float $a, 37 ? String $b, 38 ?ITERABLE $c, 39 ? Object $d, 40 ?Foo\Bar $e 41) : ?Foo\Bar {} 42 43$foo = function (?Int $a, ? Callable $b) 44 :?INT{}; 45 46$var = (BInARY) $string; 47$var = (binary)$string; 48 49function unionParamTypesA (bool|array| /* nullability operator not allowed in union */ NULL $var) {} 50 51function unionParamTypesB (\Package\ClassName | Int | \Package\Other_Class | FALSE $var) {} 52 53function unionReturnTypesA ($var): bool|array| /* nullability operator not allowed in union */ NULL {} 54 55function unionReturnTypesB ($var): \Package\ClassName | Int | \Package\Other_Class | FALSE {} 56 57class TypedProperties 58{ 59 protected ClassName $class; 60 public Int $int; 61 private ?BOOL $bool; 62 public Self $self; 63 protected PaRenT $parent; 64 private ARRAY $array; 65 public Float $float; 66 protected ?STRING $string; 67 private IterablE $iterable; 68 public Object $object; 69 protected Mixed $mixed; 70 71 public Iterable|FALSE|NULL $unionTypeA; 72 protected SELF|Parent /* comment */ |\Fully\Qualified\ClassName|UnQualifiedClass $unionTypeB; 73 private ClassName|/*comment*/Float|STRING|False $unionTypeC; 74 public sTRing | aRRaY | FaLSe $unionTypeD; 75} 76 77class ConstructorPropertyPromotionWithTypes { 78 public function __construct(protected Float|Int $x, public ?STRING &$y = 'test', private mixed $z) {} 79} 80 81class ConstructorPropertyPromotionAndNormalParams { 82 public function __construct(public Int $promotedProp, ?Int $normalArg) {} 83} 84