rfc:typehint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

rfc:typehint [2008/04/08 00:20]
felipe created
rfc:typehint [2017/09/22 13:28]
Line 1: Line 1:
-====== Request for Comments: Return value and parameter type hint ====== 
-  * Version: 1.0 
-  * Date: 2008-04-07 
-  * Author: Felipe Pena <felipensp@gmail.com> 
-  * Status: Under Discussion 
- 
-===== Parameter type hint - Examples ===== 
-=== integer / int === 
-<code php> 
-function test(integer $value) { 
-} 
- 
-test(1); 
-test("1337"); 
-test(-1); 
-test("1."); // Catchable fatal error: Argument 1 passed to test() must be an integer, string given 
- 
-function test(integer $value = '1') { 
-} 
-// Fatal error: Default value for parameters with integer type hint can only be the exact type or NULL 
-</code> 
- 
-=== double / float / real === 
-<code php> 
-function test(double $value) { 
-} 
- 
-test(1.1); 
-test(.1); 
-test("1."); 
-test("1337"); // Catchable fatal error: Argument 1 passed to test() must be an double, string given 
- 
-function test(double $value = '1') { 
-} 
-// Fatal error: Default value for parameters with double type hint can only be the exact type or NULL 
-</code> 
- 
-=== bool / boolean === 
-<code php> 
-function test(bool $value = true) { 
-} 
- 
-test(false); 
-test(0); 
-test(1); 
-test('0'); 
-test('1'); 
-test(''); 
-test(null); // Catchable fatal error: Argument 1 passed to test() must be an boolean, null given 
-</code> 
- 
-=== resource === 
-<code php> 
-function test(resource $value) { 
-} 
- 
-test(fopen(__FILE__, 'r')); 
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an resource, null given 
-</code> 
- 
-=== object === 
-<code php> 
-function test(object $value) { 
-} 
- 
-test(new stdclass); 
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an object, null given 
- 
-function test(object $value = 1) { 
-} 
-// Fatal error: Default value for parameters with object type hint can only be the exact type or NULL 
-</code> 
- 
- 
-===== Proposal and Patch ===== 
- 
-Parameter type hint:  
- 
  
rfc/typehint.txt · Last modified: 2017/09/22 13:28 (external edit)