rfc:empty_isset_exprs

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:empty_isset_exprs [2012/04/12 21:39] – created nikicrfc:empty_isset_exprs [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 2: Line 2:
   * Date: 2012-04-12   * Date: 2012-04-12
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
-  * Status: Under Discussion+  * Status: Implemented 
 +  * Original discussion: http://markmail.org/thread/gnci76ugtwda2t42 (Apr 10, 2012 3:53 pm) 
 +  * RFC announcement: http://markmail.org/thread/ju2jyrenxkeddrnt (Apr 12, 2012 2:42 pm)
  
 ==== Summary ==== ==== Summary ====
Line 13: Line 15:
 but it is not possible to write ''empty(foo())''. but it is not possible to write ''empty(foo())''.
  
-Trying to do so results in this not pariculary helpful error message: "Can't use function return value in write context".+Trying to do so results in this not particularly helpful error message: "Can't use function return value in write context".
  
 For other expressions (not variables and not function calls) a parse error is thrown. For other expressions (not variables and not function calls) a parse error is thrown.
Line 23: Line 25:
  
 As for function calls (and other expressions) it is already known that the value exists, using ''empty()''/''isset()'' is As for function calls (and other expressions) it is already known that the value exists, using ''empty()''/''isset()'' is
-not necessary and ''!func()''/''func() !== null'' can be used instead instead.+not necessary and ''!func()''/''func() !== null'' can be used instead.
  
 ==== Why should we change the behavior? ==== ==== Why should we change the behavior? ====
Line 37: Line 39:
  
 The patch is available as a PR on Github: https://github.com/php/php-src/pull/54 The patch is available as a PR on Github: https://github.com/php/php-src/pull/54
 +
 +==== Change only empty()? ====
 +
 +After further discussion it seems like it might be better to only add expression support for ''empty()'', but not for ''isset()''. The
 +original RFC included ''isset()'', because changing only one of the language constructs seemed inconsistent (as they are so similar).
 +
 +On the other hand, using ''isset()'' on function calls and other expressions doesn't seem particularly useful. ''isset(someFunction())''
 +is semantically unclear (how can ''someFunction()'' not be set?) and could be interpreted as a check whether the function itself exists.
 +
 +Allowing ''isset()'' to accept expressions would probably only cause confusion.
 +
 +==== Vote ====
 +
 +<doodle 
 +title="Which of the language constructs should accept arbitrary arguments?" auth="nikic" voteType="single" closed="True">
 +   * Both empty() and isset()
 +   * Only empty()
 +   * None
 +</doodle>
 +
 +The previous vote is obsolete and is left here only for reference:
 +
 +<doodle 
 +title="Should empty() and isset() accept arbitrary arguments?" auth="nikic" voteType="single" closed="True">
 +   * yes
 +   * no
 +</doodle>
 +
 +==== Result ====
 +
 +The RFC was accepted with the option "Only empty()". The relevant commit it https://github.com/php/php-src/commit/ec061a93c53c8cde10237741e98e992c1a05d148.
rfc/empty_isset_exprs.1334266745.txt.gz · Last modified: 2017/09/22 13:28 (external edit)