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
Next revisionBoth sides next revision
rfc:counting_non_countables [2016/10/04 09:40] – Added mailing list link duncan3dcrfc:counting_non_countables [2016/11/04 23:15] – Update status to Accepted duncan3dc
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 =====
  
 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'
 +
 +===== Vote =====
 +
 +<doodle title="Counting of non-countable objects" auth="duncan3dc" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
  
 Patch to handle the change: Patch to handle the change:
-https://github.com/duncan3dc/php-src/commit/73f6dfbf1eefa65f3a0aa9156bcad1291520f0ea+https://github.com/duncan3dc/php-src/commit/ea03689a800dfeb0b94b0b7a2a0ed837c280f27f
  
-Example test+Example tests
-https://github.com/duncan3dc/php-src/commit/2741d8f518f6e0963c9a98a1e8954bee81e23e1b+https://github.com/duncan3dc/php-src/commit/3e4fa60b63c94a7015d09f7310e6653ece86db05
  
 =====References ===== =====References =====
rfc/counting_non_countables.txt · Last modified: 2018/03/01 23:26 by carusogabriel