note 117906 added to functions.returning-values
| From: | ryan dot jentzsch at gmail dot com | Date: | Sun, 30 Aug 2015 06:12:51 +0000 |
| Subject: | note 117906 added to functions.returning-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203525@lists.php.net to get a copy of this message | ||
PHP 7 return types if specified can not return a null.
For example:
<?php
declare(strict_types=1);
function add2ints(int $x, int $y):int
{
$z = $x + $y;
if ($z===0)
{
return null;
}
return $z;
}
$a = add2ints(3, 4);
echo is_null($a) ? 'Null' : $a;
$b = add2ints(-2, 2);
echo is_null($b) ? 'Null' : $b;
exit();
Output:
7
Process finished with exit code 139
----
Server IP: 72.52.91.14
Probable Submitter: 71.219.50.169
----
Manual Page -- http://php.net/manual/en/functions.returning-values.php
Edit -- https://master.php.net/note/edit/117906
Del: integrated -- https://master.php.net/note/delete/117906/integrated
Del: useless -- https://master.php.net/note/delete/117906/useless
Del: bad code -- https://master.php.net/note/delete/117906/bad+code
Del: spam -- https://master.php.net/note/delete/117906/spam
Del: non-english -- https://master.php.net/note/delete/117906/non-english
Del: in docs -- https://master.php.net/note/delete/117906/in+docs
Del: other reasons-- https://master.php.net/note/delete/117906
Reject -- https://master.php.net/note/reject/117906
Search -- https://master.php.net/manage/user-notes.php