rfc:typehint

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:typehint [2008/04/16 16:29]
felipe New informations.
rfc:typehint [2017/09/22 13:28] (current)
Line 3: Line 3:
   * Date: 2008-04-07   * Date: 2008-04-07
   * Author: Felipe Pena <felipensp@gmail.com>   * Author: Felipe Pena <felipensp@gmail.com>
-  * Status: Under Discussion+  * Status: [[http://news.php.net/php.internals/37049|Under Discussion]] 
  
 ====== Details of implementation ====== ====== Details of implementation ======
 **Parameter type hint:** **Parameter type hint:**
-  - The behavior when the default value is NULL was keeped.+  - The behavior when the default parameter value is ''NULL'' was kept.
 **Both:** **Both:**
   - Binary and unicode string are specified by ''string''.   - Binary and unicode string are specified by ''string''.
Line 15: Line 16:
 ==== BC Break ==== ==== BC Break ====
 No BC break using the "(type)" syntax. (Inspirated by Objective-C) No BC break using the "(type)" syntax. (Inspirated by Objective-C)
 +
  
 ==== Examples ==== ==== Examples ====
Line 96: Line 98:
 } }
  
-test('1337'); +test('1337'); // Catchable fatal error: The returned value must be of the type integer
-test(-1); +
-test(1); +
-test(1.); // Catchable fatal error: The returned value must be of the type integer+
 </code> </code>
  
Line 130: Line 129:
       - isObject()       - isObject()
       - isResource()       - isResource()
 +
 +
  
 ==== Examples ==== ==== Examples ====
 +
 +=== With default parameter value ===
 +<code php>
 +function test(integer $value = '1') {
 +}
 +// Fatal error: Default value for parameters with integer type hint can only be the exact type or NULL
 +</code>
  
 === integer / int === === integer / int ===
Line 139: Line 147:
  
 test(1); test(1);
-test("1337"); 
 test(-1); test(-1);
-test("1."); // Catchable fatal error: Argument 1 passed to test() must be an integer, string given +test("1.");  
- +// Catchable fatal error: Argument 1 passed to test() must be of the type 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> </code>
  
Line 155: Line 159:
 test(1.1); test(1.1);
 test(.1); test(.1);
-test("1."); +test("1."); // Catchable fatal error: Argument 1 passed to test() must be of the type double, string given
-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> </code>
  
Line 169: Line 168:
  
 test(false); test(false);
-test(0); +test(0); // Catchable fatal error: Argument 1 passed to test() must be of the type boolean, null given
-test(1); +
-test('0'); +
-test('1'); +
-test(''); +
-test(null); // Catchable fatal error: Argument 1 passed to test() must be an boolean, null given+
 </code> </code>
  
Line 183: Line 177:
  
 test(fopen(__FILE__, 'r')); test(fopen(__FILE__, 'r'));
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an resource, null given+test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type resource, null given
 </code> </code>
  
Line 192: Line 186:
  
 test(new stdclass); test(new stdclass);
-test(NULL); // Catchable fatal error: Argument 1 passed to test() must be an object, null given +test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type 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> </code>
  
  
  
-===== Patches =====+===== Patches & tests =====
  
-  - Return value type hint: http://felipe.ath.cx/diff/return_type_hint.diff (under construction) +  - Return value type hint: http://felipe.ath.cx/diff/return_type_hint.diff 
-  - Parameter type hint: http://felipe.ath.cx/diff/param_type_hint.diff (under construction)+  - Parameter type hint: http://felipe.ath.cx/diff/param_type_hint.diff 
 +  - Tests: http://felipe.ath.cx/diff/tests/
  
rfc/typehint.1208363383.txt.gz · Last modified: 2017/09/22 13:28 (external edit)