September 2016
Intermediate to advanced
1091 pages
21h 41m
English
PHP 7 allows you to specify a data type for the return value of a function. Unlike scalar type hinting, however, you don't need to add any special declarations.
function returnsString(DateTime $date, $format) : string
{
return $date->format($format);
}PHP 7.1 introduced a variation on return data typing called nullable types. All you need to do is to change string to ?string. This allows the function to return either string or NULL.
Read now
Unlock full access