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

From: Date: Sun, 13 Apr 2014 17:20:19 +0000
Subject: Bug #67064 [Opn->Asn]: Countable interface prevents using 2nd parameter ($mode) of count() function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185212@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:             Open
+Status:             Assigned
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows 7 64 bit
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        bwoebi
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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 (#185212) next »