rfc:get_class_disallow_null_parameter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:get_class_disallow_null_parameter [2016/08/13 22:56] – danack | rfc:get_class_disallow_null_parameter [2018/03/01 23:26] (current) – RFC was implemented in PHP 7.2 carusogabriel | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: get_class() disallow null parameter ====== | ====== PHP RFC: get_class() disallow null parameter ====== | ||
- | * Version: | + | * Version: |
* Date: 2016-08-12 | * Date: 2016-08-12 | ||
* Author: Danack | * Author: Danack | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 26: | Line 26: | ||
If $result contains null, the output will be of the class context where get_class() was called from, in this case " | If $result contains null, the output will be of the class context where get_class() was called from, in this case " | ||
+ | |||
+ | |||
+ | This feature violates the [[https:// | ||
+ | |||
===== Proposal ===== | ===== Proposal ===== | ||
- | Disallow null being passed to the function as a valid parameter. | + | Disallow null being passed to the function as a valid parameter. |
+ | |||
+ | < | ||
+ | Warning: get_class() expects parameter 1 to be object, null given in %s on line %d | ||
+ | </ | ||
I.e. the valid ways to call the function will be: | I.e. the valid ways to call the function will be: | ||
Line 53: | Line 61: | ||
<code php> | <code php> | ||
if ($some_value_that_may_be_null === null) { | if ($some_value_that_may_be_null === null) { | ||
- | $x = null; | + | $x = get_class(); |
} | } | ||
else { | else { | ||
Line 63: | Line 71: | ||
7.2 | 7.2 | ||
- | ===== Proposed | + | ===== Voting ===== |
- | The voting question will be "Should the function be changed to disallow null being passed as a parameter?" with yes/no being the options. | + | Should the get_class() |
- | ===== Patches and Tests ===== | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
- | https:// | + | Voting ended on the 8th October 2016 9pm UTC |
- | ===== Implementation | + | ===== null vs default param ===== |
- | After the project is implemented, | + | |
- | - the version(s) it was merged to | + | |
- | - a link to the git commit(s) | + | |
- | - a link to the PHP manual entry for the feature | + | |
+ | When this topic was discussed before, it came as a surprise to some people that PHP can tell the difference between passing null and having a default value be null. This is perfectly possible in both internal code, as well as userland code: | ||
+ | <code php> | ||
+ | function get_class($item = null) | ||
+ | { | ||
+ | if (func_num_args() == 0) { | ||
+ | return get_current_scope_name(); | ||
+ | } | ||
+ | if ($item === null) { | ||
+ | trigger_error(" | ||
+ | } | ||
+ | if (is_object($item) == false) { | ||
+ | trigger_error(" | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | return gettype($item); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Patches and Tests ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ===== Implementation ===== | ||
+ | After the project is implemented, | ||
+ | - This was merged for PHP 7.2 | ||
+ | - https:// | ||
+ | - https:// |
rfc/get_class_disallow_null_parameter.1471129016.txt.gz · Last modified: 2017/09/22 13:28 (external edit)