rfc:safe_cast
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:safe_cast [2014/11/19 20:37] – No 29th November ^^ ajf | rfc:safe_cast [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Safe Casting Functions ====== | ====== PHP RFC: Safe Casting Functions ====== | ||
- | * Version: 0.1.7 | + | * Version: 0.1.8 |
* Date: 2014-10-20, Last Updated 2014-11-14 | * Date: 2014-10-20, Last Updated 2014-11-14 | ||
* Author: Andrea Faulds, ajf@ajf.me | * Author: Andrea Faulds, ajf@ajf.me | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 9: | Line 9: | ||
Currently, PHP only provides one means of type conversion: explicit casts. These casts never fail or emit errors, making them dangerous to use, as when passed garbage input, they will simply return garbage instead of indicating that something went wrong. This makes it difficult to write robust applications which handle user data. They also prevent any suggestion of strict type hinting for scalar types, because if that were to be added, users would simply use dangerous explicit casts to get around errors and the result would be code that is buggier than it would have been without type hinting at all. | Currently, PHP only provides one means of type conversion: explicit casts. These casts never fail or emit errors, making them dangerous to use, as when passed garbage input, they will simply return garbage instead of indicating that something went wrong. This makes it difficult to write robust applications which handle user data. They also prevent any suggestion of strict type hinting for scalar types, because if that were to be added, users would simply use dangerous explicit casts to get around errors and the result would be code that is buggier than it would have been without type hinting at all. | ||
+ | |||
+ | For int and float conversion specifically, | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 14: | Line 16: | ||
Two families of "safe casting" | Two families of "safe casting" | ||
- | '' | + | '' |
- | '' | + | '' |
'' | '' | ||
Line 92: | Line 94: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | While I'd prefer to return NULL on error, it would also be possible to return FALSE. As this seems to be relatively controversial, | + | None. |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 108: | Line 110: | ||
==== Vote ==== | ==== Vote ==== | ||
- | Voting opened 2014-11-19 and ends 2014-12-01. | + | Voting opened 2014-11-19 and ended 2014-11-29. |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 139: | Line 141: | ||
===== Changelog ===== | ===== Changelog ===== | ||
+ | * v0.1.8 - ext/filter note in Introduction | ||
* v0.1.7 - Allow positive signs | * v0.1.7 - Allow positive signs | ||
* v0.1.6 - Dropped zero round trip data loss principle, added octal and whitespace rationale | * v0.1.6 - Dropped zero round trip data loss principle, added octal and whitespace rationale |
rfc/safe_cast.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1