O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 18

image

Type Hinting

PHP relies on the proper documentation of functions for developers to know what arguments a function can take. To simplify this PHP 5 introduced type hinting, which allows a function to specify the type of arguments it accepts. Allowed types include classes, interfaces and the pseudo types array and callable.

Name Description
class name Argument must be an object of this class or a child.
interface name Argument must be an object implementing this interface.
array Argument must be an array.
callable Argument must be callable as a function.

A type hint is set by prefixing the parameter with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required