note 118279 added to functions.user-defined
| From: | ohcc at 163 dot com | Date: | Sat, 07 Nov 2015 15:52:17 +0000 |
| Subject: | note 118279 added to functions.user-defined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204105@lists.php.net to get a copy of this message | ||
As of PHP 7.0, you can restrain type of return value of user defined functions.
Syntax is : function FunctionName ($arg1, $arg2, ...) : TYPE { ... }
TYPE is a string representing the type of return value, TYPE can be a class name or a php variable
type, such as array/string/bool/int/float.
When TYPE is one of the following value, it also stands for a classname
str/boolean/integer/real/double/resource/object/scalar
However,in my opion, boolean/bool, integer/int ... should have the same meaning, but at least in
PHP7, they stand for different meanings respectively. This may be fixed in later versions of PHP.
<?php
function wxc ($var) : string {
return $var;
}
?>
this function must return a string, if it return something else when called, a "Fatal error:
Uncaught TypeError" error will be triggered.
code above is supported only in PHP 7+
----
Server IP: 72.52.91.14
Probable Submitter: 118.117.77.220
----
Manual Page -- http://php.net/manual/en/functions.user-defined.php
Edit -- https://master.php.net/note/edit/118279
Del: integrated -- https://master.php.net/note/delete/118279/integrated
Del: useless -- https://master.php.net/note/delete/118279/useless
Del: bad code -- https://master.php.net/note/delete/118279/bad+code
Del: spam -- https://master.php.net/note/delete/118279/spam
Del: non-english -- https://master.php.net/note/delete/118279/non-english
Del: in docs -- https://master.php.net/note/delete/118279/in+docs
Del: other reasons-- https://master.php.net/note/delete/118279
Reject -- https://master.php.net/note/reject/118279
Search -- https://master.php.net/manage/user-notes.php