php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67064 Countable interface prevents using 2nd parameter ($mode) of count() function
Submitted: 2014-04-13 17:09 UTC Modified: 2014-08-04 08:35 UTC
From: trainmaster at gmx dot net Assigned:
Status: Closed Package: SPL related
PHP Version: Irrelevant OS: Windows 7 64 bit
Private report: No CVE-ID: None
 [2014-04-13 17:09 UTC] trainmaster at gmx dot net
Description:
------------
Implementing the countable interface does not allow to use the $mode parameter of the count() function.

I think it can be easily fixed without BC.

Test script:
---------------
class Counter implements Countable
{
    public function count()
    {
    	var_dump(func_get_arg(0));
    	return count($this->data);
    }
}

$counter = new Counter;
count($counter, COUNT_RECURSIVE);

Expected result:
----------------
// int(1)

Actual result:
--------------
// Warning: func_get_arg(): Argument 0 not passed to function

Patches

bug67064-BC (last revision 2014-06-13 13:53 UTC by mbeccati@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-13 17:17 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bwoebi
 [2014-04-13 17:17 UTC] bwoebi@php.net
When you implement an interface, you always can add an optional parameter:

    public function count($mode = COUNT_NORMAL) { ... }

should work too, when I'll fix this bug.
 [2014-04-13 17:24 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-04-13 17:24 UTC] bwoebi@php.net
-Status: Assigned +Status: Closed
 [2014-04-13 17:25 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-04-13 17:28 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-04-15 12:04 UTC] ab@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-04-15 13:05 UTC] ab@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-05-01 14:59 UTC] tyrael@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-06-13 13:53 UTC] mbeccati@php.net
The following patch has been added/updated:

Patch Name: bug67064-BC
Revision:   1402667581
URL:        https://bugs.php.net/patch-display.php?bug=67064&patch=bug67064-BC&revision=1402667581
 [2014-06-13 13:57 UTC] mbeccati@php.net
I've attached a patch that restores BC in the (very common) case when count() is called without arguments, so that Countable::count() is called rather than Countable::count(0).

It's not a big deal, but the BC break might break the application tests that expect a call without parameters. This would avoid having to do check for PHP 5.6 in such tests.
 [2014-06-13 16:42 UTC] bwoebi@php.net
I think this isn't preferable behavior. Maybe, with your patch BC is conserved in the most strict sense, but it's not the least confusing way when using this feature, I think.
 [2014-07-30 15:18 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-07-30 16:07 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-07-30 18:40 UTC] tyrael@php.net
-Status: Closed +Status: Re-Opened
 [2014-07-30 18:40 UTC] tyrael@php.net
the fix was still causing some BC concerns, so we reverted it from PHP-5.6.
see http://www.serverphorums.com/read.php?7,988818 for the discussion leading to the revert.
 [2014-08-04 08:26 UTC] ab@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-08-04 08:26 UTC] ab@php.net
-Status: Re-Opened +Status: Closed
 [2014-08-04 08:35 UTC] bwoebi@php.net
-Status: Closed +Status: Suspended -Assigned To: bwoebi +Assigned To:
 [2014-08-04 08:43 UTC] ab@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-08-04 08:43 UTC] ab@php.net
-Status: Suspended +Status: Closed
 [2014-08-04 09:59 UTC] dmitry@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-08-14 00:52 UTC] tyrael@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=354ee12b73dbe20d0c4fa7883eb34714f89109df
Log: Revert "Fix bug #67064 in a BC safe way"
 [2014-10-07 23:15 UTC] stas@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=1a4a9eede59b853f11e8e8b965e5f715f53da8f7
Log: Fix bug #67064 in a BC safe way You can use an optional parameter now when implementing the Countable interface to get the $mode passed to count().
 [2014-10-26 01:28 UTC] bjori@php.net
Automatic comment from SVN on behalf of bjori
Revision: http://svn.php.net/viewvc/?view=revision&revision=335135
Log: Revert r333536 Fixed version number in changelog
Revert r333311 Updated Countable::count([$mode]) to reflect newest changes

The fix for bug #67064 was reverted, so undocumenting the changes
 [2015-02-06 17:49 UTC] boen dot robot at gmail dot com
Will this change make it into PHP 7 at least?

(Because it's not currently, and the BC concerns don't exactly apply there...)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC