未加星标

PHP: rfc:counting_non_countables

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏
PHP RFC: Counting of non-countable objects

Version: 0.1

Date: 2016-10-04

Author: Craig Duncan [email protected]

Proposed version:php 7.2

Status: Under Discussion

ML thread: http://externals.io/thread/350

Introduction

Calling count() on an 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:

function handle_records(iterable $iterable) { if (count($iterable) === 0) { return handle_empty(); } foreach ($iterable as $value) { handle_value($val); } }

Passing a Generator that yields nothing would not call handle_empty() , or handle_value() , or alert the developer to the issue.

Proposal

This RFC proposes raising a warning when attempting to count an object that doesn't implement Countable.

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.

Proposed PHP Version(s)

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

Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.

Patches and Tests

Patch to handle the change: https://github.com/duncan3dc/php-src/commit/73f6dfbf1eefa65f3a0aa9156bcad1291520f0ea

Example test: https://github.com/duncan3dc/php-src/commit/2741d8f518f6e0963c9a98a1e8954bee81e23e1b

References

Initial discussion that led to this RFC 's creation: https://github.com/php/php-src/pull/1672

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

主题: PHP
分页:12
转载请注明
本文标题:PHP: rfc:counting_non_countables
本站链接:http://www.codesec.net/view/479727.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(48)