rfc:parameter_type_casting_hints
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:parameter_type_casting_hints [2012/03/04 01:04] – [Syntax] ircmaxell | rfc:parameter_type_casting_hints [2012/03/08 00:53] – Withdraw RFC ircmaxell | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2012-03-03 | * Date: 2012-03-03 | ||
* Author: Anthony Ferrara < | * Author: Anthony Ferrara < | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
* Patch: https:// | * Patch: https:// | ||
Line 14: | Line 14: | ||
This RFC discusses a method of adding scalar type hints to PHP while attempting to embrace the dynamic nature of PHP variables. | This RFC discusses a method of adding scalar type hints to PHP while attempting to embrace the dynamic nature of PHP variables. | ||
+ | |||
+ | It's worth noting that this RFC does not attempt to add new errors to the casting paradigm in PHP. It's my feeling that issuing errors (E_NOTICE or E_STRICT) on data-loss from cast operations is important, but a more general issue to PHP. So as such it does not fall under this specific RFC, but as a more general RFC which can be added to the language as a whole. | ||
+ | |||
+ | So in an attempt at consistency, | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 23: | Line 27: | ||
<?php | <?php | ||
- | function test((int) $intParam, (string) $strParam = " | + | function test((int) $intParam, (string) $strParam = " |
?> | ?> | ||
Line 51: | Line 55: | ||
Note that the final 2 options (array and object) are there for both completeness, | Note that the final 2 options (array and object) are there for both completeness, | ||
+ | |||
+ | ==== Default Values ==== | ||
+ | |||
+ | For consistency, | ||
+ | |||
+ | If '' | ||
+ | |||
+ | function test1((int) $foo) { echo gettype($foo); | ||
+ | function test2((int) $foo = null) { echo gettype($foo); | ||
+ | | ||
+ | Calling '' | ||
==== Backwards compatibility breaks ==== | ==== Backwards compatibility breaks ==== | ||
Line 62: | Line 77: | ||
The patch adds a series of " | The patch adds a series of " | ||
- | '' | + | * '' |
- | '' | + | |
- | '' | + | |
- | '' | + | |
- | '' | + | |
- | '' | + | |
- | '' | + | |
These are used to distinguish casting declarations in OPCode from a possible future implementation of more strict casts. | These are used to distinguish casting declarations in OPCode from a possible future implementation of more strict casts. | ||
These have also been added to the '' | These have also been added to the '' | ||
- | |||
==== API Changes ==== | ==== API Changes ==== | ||
Line 81: | Line 95: | ||
To prevent odd behavior, it is a '' | To prevent odd behavior, it is a '' | ||
- | |||
- | ==== Default Values ==== | ||
- | |||
- | For consistency, | ||
==== Parser Tokens ==== | ==== Parser Tokens ==== | ||
Line 91: | Line 101: | ||
===== Changelog ===== | ===== Changelog ===== | ||
- |
rfc/parameter_type_casting_hints.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1