Skip to content

Commit 1a4a9ee

Browse files
committed
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().
1 parent 5a0da28 commit 1a4a9ee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ext/standard/array.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ PHP_FUNCTION(count)
333333
#ifdef HAVE_SPL
334334
/* if not and the object implements Countable we call its count() method */
335335
if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) {
336-
zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval);
336+
zval *mode_zv;
337+
MAKE_STD_ZVAL(mode_zv);
338+
Z_LVAL_P(mode_zv) = mode;
339+
zend_call_method_with_1_params(&array, NULL, NULL, "count", &retval, mode_zv);
337340
if (retval) {
338341
convert_to_long_ex(&retval);
339342
RETVAL_LONG(Z_LVAL_P(retval));
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #67064 ()
3+
--FILE--
4+
<?php
5+
class Counter implements Countable {
6+
public function count($mode = COUNT_NORMAL) {
7+
var_dump($mode == COUNT_RECURSIVE);
8+
return 1;
9+
}
10+
}
11+
12+
$counter = new Counter;
13+
var_dump(count($counter, COUNT_RECURSIVE));
14+
?>
15+
--EXPECTF--
16+
bool(true)
17+
int(1)

0 commit comments

Comments
 (0)