Bug #67064 [Asn->Csd]: Countable interface prevents using 2nd parameter ($mode) of count() function

From: Date: Sun, 13 Apr 2014 17:27:37 +0000
Subject: Bug #67064 [Asn->Csd]: Countable interface prevents using 2nd parameter ($mode) of count() function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185213@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67064&edit=1

 ID:                 67064
 Updated by:         bwoebi@php.net
 Reported by:        trainmaster at gmx dot net
 Summary:            Countable interface prevents using 2nd parameter
                     ($mode) of count() function
-Status:             Assigned
+Status:             Closed
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows 7 64 bit
 PHP Version:        Irrelevant
 Assigned To:        bwoebi
 Block user comment: N
 Private report:     N

 New Comment:

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().


Previous Comments:
------------------------------------------------------------------------
[2014-04-13 17:17:32] 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:09:03] 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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=67064&edit=1


Thread (11 messages)

« previous php.bugs (#185213) next »