Type Hinting
- Primitive types: int, float, bool, string.
- Classes and interfaces: Any class or interface name.
- Arrays: with the array keyword.
- Callable: for functions or objects that implement the invoke method.
- Nullable types: by prefixing with a ?.
- Iterables: with the iterable keyword, which includes both arrays and objects implementing the
Traversable interface. - Union types: introduced in PHP 8, where a parameter can accept multiple types.
// Type Hinting - int, float, bool, string
function myage(int $age){ echo $age."\n"; } myage(5);