rfc:nullsafe_operator

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
rfc:nullsafe_operator [2020/07/16 07:54] – Disallow ?-> in write context ilutovrfc:nullsafe_operator [2020/07/31 08:55] (current) – Close vote ilutov
Line 3: Line 3:
   * Date: 2020-06-02   * Date: 2020-06-02
   * Author: Ilija Tovilo, tovilo.ilija@gmail.com   * Author: Ilija Tovilo, tovilo.ilija@gmail.com
-  * Status: Under discussion+  * Status: Implemented
   * Target Version: PHP 8.0   * Target Version: PHP 8.0
   * Implementation: https://github.com/php/php-src/pull/5619   * Implementation: https://github.com/php/php-src/pull/5619
Line 79: Line 79:
 The following elements will cause new sub-chains. The following elements will cause new sub-chains.
  
-  * Right hand side of an assignment 
   * Arguments in a function call   * Arguments in a function call
   * The expression in ''%%[]%%'' of an array access   * The expression in ''%%[]%%'' of an array access
Line 110: Line 109:
 $foo?->bar(expensive_function()); $foo?->bar(expensive_function());
 </code> </code>
-The evaluation of ''%%expensive_function()%%'' is undesirable if ''%%$foo%%'' is ''%%null%%'' as its result will simply be discarded. If the function has side effects it could also lead to surpsises.+The evaluation of ''%%expensive_function()%%'' is undesirable if ''%%$foo%%'' is ''%%null%%'' as its result will simply be discarded. If the function has side effects it could also lead to surprises.
  
 **2. You can see which methods/properties return null** **2. You can see which methods/properties return null**
Line 155: Line 154:
 |[[https://docs.hhvm.com/hack/expressions-and-operators/member-selection#null-safe-member-access|Hack]]          |✓                    |?->   |✗‡                  | |[[https://docs.hhvm.com/hack/expressions-and-operators/member-selection#null-safe-member-access|Hack]]          |✓                    |?->   |✗‡                  |
  
-* In Object-C accessing properties and calling methods on ''%%nil%%'' is always ignored † Possible via [[https://github.com/ThoughtWorksInc/Dsl.scala/blob/master/keywords-NullSafe/src/main/scala/com/thoughtworks/dsl/keywords/NullSafe.scala|DSL]] ‡ Hack evaluates method arguments even if the left hand side of ''%%?->%%'' is ''%%null%%''+* In Object-C accessing properties and calling methods on ''%%nil%%'' is always ignored\\ 
 +† Possible via [[https://github.com/ThoughtWorksInc/Dsl.scala/blob/master/keywords-NullSafe/src/main/scala/com/thoughtworks/dsl/keywords/NullSafe.scala|DSL]]\\ 
 +‡ Hack evaluates method arguments even if the left hand side of ''%%?->%%'' is ''%%null%%''
  
 8/13 languages have a nullsafe operator. 4/8 of those implement the nullsafe operator with short circuiting. 8/13 languages have a nullsafe operator. 4/8 of those implement the nullsafe operator with short circuiting.
Line 161: Line 162:
 ===== Syntax choice ===== ===== Syntax choice =====
  
-The ''%%?%%'' in ''%%?->%%'' denotes the precise place in the code where the short circuiting occurs. It closesly resembles the syntax of every other language that implements a nullsafe operator.+The ''%%?%%'' in ''%%?->%%'' denotes the precise place in the code where the short circuiting occurs. It closely resembles the syntax of every other language that implements a nullsafe operator.
  
 ===== Forbidden usages ===== ===== Forbidden usages =====
Line 182: Line 183:
 // Assignments can only happen to writable values // Assignments can only happen to writable values
 </code> </code>
-It was previously suggested to allow the nullsafe operator in the left hand side of assignments and skip the assignment if the left hand side of the nullsafe operator was ''%%null%%''. However, due to technical difficulties this is not a part of this RFC. It might be addressed in a later RFC.+It was previously suggested to allow the nullsafe operator in the left hand side of assignments and skip the assignment if the left hand side of the nullsafe operator was ''%%null%%''. However, due to technical difficulties this is not a part of this RFC. It might be addressed in a later RFC. It is also not completely clear whether the right hand side of the assignment should always be evaluated or not.
  
 ==== References ==== ==== References ====
Line 231: Line 232:
 ===== Vote ===== ===== Vote =====
  
-Voting starts 2020-xx-xx and ends 2020-xx-xx+Voting starts 2020-07-17 and ends 2020-07-31
  
 <doodle title="Add nullsafe operator to the language?" auth="ilutov" voteType="single" closed="true"> <doodle title="Add nullsafe operator to the language?" auth="ilutov" voteType="single" closed="true">
rfc/nullsafe_operator.1594886040.txt.gz · Last modified: 2020/07/16 07:54 by ilutov