|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2014-10-01 19:43 UTC] requinix@php.net
 
-Package: PHP Language Specification
+Package: *General Issues
  [2014-10-01 19:43 UTC] requinix@php.net
  [2014-10-15 16:03 UTC] tyrael@php.net
 
-PHP Version: 5.6.0
+PHP Version: 7.0
  [2014-10-15 16:03 UTC] tyrael@php.net
 
-Operating System: Linux
+Operating System:
  [2015-02-25 01:07 UTC] edgar dot r dot sandi at gmail dot com
  [2015-02-25 01:14 UTC] requinix@php.net
 
-Status:      Open
+Status:      Closed
-Assigned To:
+Assigned To: requinix
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
Description: ------------ It would be useful to optionally be able define a return type for a function, perhaps like so: function foo($arg1, $arg2) returns array { ... } Currently the Code by Contract principle is not fully implementable in interfaces because there is no way to guarantee a return type for functions, or even any return value at all. Adding a return type would allow one to do better code by contract: interface iMyInterface { function handle_data($arg1) returns iMyResponse; } interface iMyResponse { ... } When writing code that implements or depends on iMyInterface, I can know what type I will be getting out of the handle_data method. Optionally one could specify multiple return types: function my_string_function($string) returns string, boolean {...} As the author of the function, I will know if I have a logic error when this function I've written doesn't return the pre-defined types and I get an error. As a client programer (who will later use the above function, but hasn't written it), I will know at a glance what output I can expect from a function, without scanning through the body to deduce it. For backwards compatibility, flexibility and php-ishness, I don't think this should be required, but optional. function my_string_function_1() {...} function my_string_function_2() returns string, boolean {...} function my_string_function_3() returns string, boolean, array {...} Test script: --------------- <?php function my_string_function($string) returns array, string, boolean { // do nothing; syntax presently invalid. }