rfc:counting_non_countables

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
Last revisionBoth sides next revision
rfc:counting_non_countables [2016/10/04 09:40] – Added mailing list link duncan3dcrfc:counting_non_countables [2017/09/22 13:28] – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHP RFC: Counting of non-countable objects ====== ====== PHP RFC: Counting of non-countable objects ======
-  * Version: 0.1+  * Version: 0.4
   * Date: 2016-10-04   * Date: 2016-10-04
-  * Author: Craig Duncan <git@duncanc.co.uk>+  * Author: Craig Duncan <php@duncanc.co.uk>
   * Proposed version: PHP 7.2   * Proposed version: PHP 7.2
-  * Status: Under Discussion+  * Status: Accepted
   * ML thread: http://externals.io/thread/350   * ML thread: http://externals.io/thread/350
  
 ===== Introduction ===== ===== Introduction =====
  
-Calling ''count()'' on an object that doesn't implement the Countable interface (http://php.net/manual/en/class.countable.php) returns 1.+Calling ''count()'' on a scalar or object that doesn't implement the Countable interface (http://php.net/manual/en/class.countable.php) returns 1.
 There are no known use cases for this, and it can easily hide bugs, take the following example: There are no known use cases for this, and it can easily hide bugs, take the following example:
 <code php> <code php>
Line 19: Line 19:
  
     foreach ($iterable as $value) {     foreach ($iterable as $value) {
-        handle_value($val);+        handle_value($value);
     }     }
 } }
Line 27: Line 27:
 ===== Proposal ===== ===== Proposal =====
  
-This RFC proposes raising a warning when attempting to count an object that doesn't implement Countable.+This RFC proposes adding a warning when calling ''count()'' with a parameter that is a scalar, null, or an object that doesn't implement Countable. 
 + 
 +//Note that the sizeof alias is also affected.// http://php.net/manual/en/function.sizeof.php
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-Counting objects that don't implement the Countable interface will still work, so the only BC will be in cases where userland convert warnings to Exceptions.+The call to ''count()'' will still return 1 (or 0 for null) so backwards compatibility is maintained. 
 + 
 +Environments that display warnings or convert them to more severe errors/exceptions would be affected, but this should just bring attention to a bug in the code.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
  
 PHP 7.2 PHP 7.2
- 
-===== Open Issues ===== 
- 
-  * Should we deprecate instead, and then disable in 8.0 
-  * Does introducing a warning in a minor release qualify as breaking BC 
- 
-===== Unaffected PHP Functionality ===== 
- 
-Counting scalars is unaffected and will still return ''1''. 
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
Line 50: Line 45:
 Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted' Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'
  
-===== Patches and Tests =====+===== Vote =====
  
-Patch to handle the change: +<doodle title="Counting of non-countable objects" auth="duncan3dc" voteType="single" closed="true"> 
-https://github.com/duncan3dc/php-src/commit/73f6dfbf1eefa65f3a0aa9156bcad1291520f0ea+   * Yes 
 +   * No 
 +</doodle>
  
-Example test+===== Implementation ===== 
-https://github.com/duncan3dc/php-src/commit/2741d8f518f6e0963c9a98a1e8954bee81e23e1b+ 
 +Pull request to handle the change
 +https://github.com/php/php-src/pull/2185
  
 =====References ===== =====References =====
Line 62: Line 61:
 Initial discussion that led to this RFC's creation: Initial discussion that led to this RFC's creation:
 https://github.com/php/php-src/pull/1672 https://github.com/php/php-src/pull/1672
 +
 +Discussion thread:
 +http://externals.io/thread/350
 +
 +Voting thread:
 +http://externals.io/thread/409
  
rfc/counting_non_countables.txt · Last modified: 2018/03/01 23:26 by carusogabriel