rfc:typehint
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:typehint [2008/04/17 14:36] – felipe | rfc:typehint [2008/04/17 14:40] – Change examples felipe | ||
---|---|---|---|
Line 128: | Line 128: | ||
- isObject() | - isObject() | ||
- isResource() | - isResource() | ||
+ | |||
==== Examples ==== | ==== Examples ==== | ||
+ | |||
+ | === With default parameter value === | ||
+ | <code php> | ||
+ | function test(integer $value = ' | ||
+ | } | ||
+ | // Fatal error: Default value for parameters with integer type hint can only be the exact type or NULL | ||
+ | </ | ||
=== integer / int === | === integer / int === | ||
Line 138: | Line 146: | ||
test(1); | test(1); | ||
- | test(" | ||
test(-1); | test(-1); | ||
- | test(" | + | test(" |
- | + | // Catchable fatal error: Argument 1 passed to test() must be of the type integer, string given ... | |
- | function test(integer $value = ' | + | |
- | } | + | |
- | // Fatal error: Default value for parameters with integer type hint can only be the exact type or NULL | + | |
</ | </ | ||
Line 154: | Line 158: | ||
test(1.1); | test(1.1); | ||
test(.1); | test(.1); | ||
- | test(" | + | test(" |
- | test(" | + | |
- | + | ||
- | function test(double $value = ' | + | |
- | } | + | |
- | // Fatal error: Default value for parameters with double type hint can only be the exact type or NULL | + | |
</ | </ | ||
Line 168: | Line 167: | ||
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(' | + | |
- | test(' | + | |
- | test('' | + | |
- | test(null); // Catchable fatal error: Argument 1 passed to test() must be of the type boolean, null given | + | |
</ | </ | ||
Line 192: | Line 186: | ||
test(new stdclass); | test(new stdclass); | ||
test(NULL); // Catchable fatal error: Argument 1 passed to test() must be of the type 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 | ||
</ | </ | ||
rfc/typehint.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1