rfc:counting_non_countables

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:counting_non_countables [2016/10/04 09:26] – created duncan3dcrfc:counting_non_countables [2018/03/01 23:26] (current) – RFC was implemented in PHP 7.2 carusogabriel
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 PHP version: PHP 7.2 +  * Proposed version: PHP 7.2 
-  * Status: Under Discussion+  * Status: Implemented (in PHP 7.2) 
 +  * 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 18: Line 19:
  
     foreach ($iterable as $value) {     foreach ($iterable as $value) {
-        handle_value($val);+        handle_value($value);
     }     }
 } }
Line 26: 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 49: 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 61: 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.1475573184.txt.gz · Last modified: 2017/09/22 13:28 (external edit)