rfc:get_class_disallow_null_parameter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:get_class_disallow_null_parameter [2016/08/14 11:02] – change to pull request. danackrfc:get_class_disallow_null_parameter [2016/08/15 07:11] – correct BC compatibility change. danack
Line 1: Line 1:
 ====== PHP RFC: get_class() disallow null parameter ====== ====== PHP RFC: get_class() disallow null parameter ======
-  * Version: 0.9+  * Version: 1.0
   * Date: 2016-08-12   * Date: 2016-08-12
   * Author: Danack   * Author: Danack
-  * Status: Draft +  * Status: Under Discussion 
   * First Published at: https://wiki.php.net/rfc/get_class_disallow_null_parameter   * First Published at: https://wiki.php.net/rfc/get_class_disallow_null_parameter
  
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 "Foo". If $result contains null, the output will be of the class context where get_class() was called from, in this case "Foo".
 +
 +
 +This feature violates the [[https://en.wikipedia.org/wiki/Principle_of_least_astonishment|Principle of least astonishment]]: "if a necessary feature has a high astonishment factor, it may be necessary to redesign the feature."
 +
  
 ===== Proposal ===== ===== Proposal =====
  
-Disallow null being passed to the function as a valid parameter.+Disallow null being passed to the function as a valid parameter. If get_class() is called with null as the parameter, a warning will be emitted: 
 + 
 +<code> 
 +Warning: get_class() expects parameter 1 to be object, null given in %s on line %d 
 +</code>
  
 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 {
rfc/get_class_disallow_null_parameter.txt · Last modified: 2018/03/01 23:26 by carusogabriel