Type System¶
Type declarations can be added to function arguments, return values, and, as of PHP 7.4.0, class properties. They ensure that the value is of the specified type at call time, otherwise a TypeError is thrown.
<?php
function foo(A $a) : void {}
class x {
private A $p;
}
?>
See also Explore Your Types, Narrowing types for static analysis and PHP Oddities.
Related : Disjunctive Normal Form (DNF), False, Mixed, Never Type, Nullable, Object, Properties, Return Type, strict_types, True, Property Type Declaration, Typed Property, Intersection Type, Object Type, Scalar Types, Special Types, Union Type, Variables, Autowiring, Propagation, Pseudo-type, Type Coverage, Dependent Type, Gradual Type Checking, Relative Types, Standalone Types, Autocompletion, Question Mark ?, resource, Types Erasure, Type Inference, Alias Types
Added in PHP 7.0