rfc:allow_null
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:allow_null [2021/12/23 22:07] – created craigfrancis | rfc:allow_null [2022/02/20 20:19] – Possible options craigfrancis | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Allow NULL ====== | ====== PHP RFC: Allow NULL ====== | ||
- | * Version: 1.0 | + | * Version: 1.3 |
* Voting Start: ? | * Voting Start: ? | ||
* Voting End: ? | * Voting End: ? | ||
* RFC Started: 2021-12-23 | * RFC Started: 2021-12-23 | ||
- | * RFC Updated: | + | * RFC Updated: |
* Author: Craig Francis, craig# | * Author: Craig Francis, craig# | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
* GitHub Repo: https:// | * GitHub Repo: https:// | ||
Line 14: | Line 14: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | PHP 8.1 introduced "Passing | + | PHP 8.1 introduced "Deprecate passing |
- | Often //NULL// is used for undefined | + | This has introduced an inconstancy when not using // |
+ | |||
+ | In PHP //NULL// is often used to represent something; e.g. when a // | ||
<code php> | <code php> | ||
Line 27: | Line 29: | ||
</ | </ | ||
- | And //NULL// can be returned from many functions, e.g. | + | And //NULL// can be returned from functions, e.g. |
* // | * // | ||
- | * //error_get_last()// | + | * //filter_input()// |
* // | * // | ||
+ | * // | ||
* // | * // | ||
- | * // | ||
- | Currently | + | This makes it common for //NULL// to be passed to many internal functions, e.g. |
+ | |||
+ | <code php> | ||
+ | trim($name); | ||
+ | strtoupper($name); | ||
+ | strlen($name); | ||
+ | urlencode($name); | ||
+ | htmlspecialchars($name); | ||
+ | hash(' | ||
+ | preg_match('/ | ||
+ | setcookie(' | ||
+ | socket_write($socket, | ||
+ | xmlwriter_text($writer, | ||
+ | </ | ||
+ | |||
+ | Developers also use //NULL// to skip certain parameters, e.g. // | ||
+ | |||
+ | Where //NULL// has always been coerced into an empty string, the integer 0, the boolean false, etc. | ||
+ | |||
+ | Currently | ||
+ | |||
+ | Developers using // | ||
+ | |||
+ | And while individual changes are easy, there are many of them (time consuming), difficult to find, and often pointless, e.g. | ||
- | And those modifications are not easy (both in finding them, and quantity). | + | * urlencode(strval($name)); |
+ | * urlencode((string) $name); | ||
+ | * urlencode($name ?? '' | ||
- | Developers will need to either use these deprecation | + | To find these issues, developers |
- | This affects every variable | + | It's worth noting |
===== Proposal ===== | ===== Proposal ===== | ||
- | To make upgrading easier, we could either: | + | There are 3 possible approaches: |
- | - Allow //NULL// when //strict_types// is not being used; | + | - NULL triggers a Fatal Error with strict_types=1, |
- | - Update some of the internal | + | - NULL triggers a Fatal Error for everyone, but update some parameters to explicitly allow NULL (e.g. //?string//). |
+ | - NULL triggers a Fatal Error for everyone (forget about backwards compatibility). | ||
+ | |||
+ | This needs to be done before the eventual end of the deprecation period, and //TypeError// exceptions are thrown. | ||
+ | |||
+ | If we choose to " | ||
+ | |||
+ | There is also a [[https:// | ||
+ | |||
+ | ===== Decision Process ===== | ||
+ | |||
+ | Does //NULL// for this parameter justify a Fatal Error? e.g. | ||
+ | |||
+ | - // | ||
+ | - // | ||
+ | - // | ||
+ | - //hash()// should **accept** //NULL// for // | ||
+ | - // | ||
+ | - // | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | N/A | + | None |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | PHP 8.1 | + | PHP 8.2 |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 74: | Line 119: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | TODO | + | Is the [[https:// |
===== Future Scope ===== | ===== Future Scope ===== | ||
- | TODO | + | Some function parameters could be updated to complain when an //NULL// **or** //Empty String// is provided; e.g. //$method// in // |
===== Voting ===== | ===== Voting ===== | ||
Line 86: | Line 131: | ||
TODO | TODO | ||
- | ===== Patches and Tests ===== | + | ===== Tests ===== |
- | TODO | + | To get and **Test** the list of functions, I wrote a script to // |
===== Implementation ===== | ===== Implementation ===== | ||
- | TODO | + | https:// |
- | ===== Rejected Features ===== | + | This patch defines // |
- | TODO | + | It works a bit like // |
+ | It's a fairly easy drop in replacement for // | ||
+ | ===== Rejected Features ===== | ||
- | --- | + | TODO |
- | ====== Notes ====== | + | ===== Notes ===== |
- | Interesting | + | Interesting the example quote from [[http:// |
> PHP is and should remain: | > PHP is and should remain: | ||
Line 110: | Line 157: | ||
> 2) a loosely typed language | > 2) a loosely typed language | ||
> 3) a language which caters to the skill-levels and platforms of a wide range of users | > 3) a language which caters to the skill-levels and platforms of a wide range of users | ||
- | |||
- | |||
- | |||
- | grep -h -r -E ' | ||
- | |||
- | Search | ||
- | ^(\s*(ZEND_FUNCTION|PHP_FUNCTION|static void).*\n)*(ZEND_FUNCTION\(|PHP_FUNCTION\(|static void *)(.+? | ||
- | Replace | ||
- | $4 | ||
rfc/allow_null.txt · Last modified: 2022/04/05 17:49 by craigfrancis