php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #67064
Patch bug67064-BC revision 2014-06-13 13:53 UTC by mbeccati@php.net

Patch bug67064-BC for SPL related Bug #67064

Patch version 2014-06-13 13:53 UTC

Return to Bug #67064 | Download this patch
Patch Revisions:

Developer: mbeccati@php.net

diff --git a/ext/standard/array.c b/ext/standard/array.c
index cbcaaf5..ca82f90 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -307,8 +307,9 @@ PHP_FUNCTION(count)
 {
        zval *array;
        long mode = COUNT_NORMAL;
+       int argc = ZEND_NUM_ARGS();

-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE) {
+       if (zend_parse_parameters(argc TSRMLS_CC, "z|l", &array, &mode) == FAILURE) {
                return;
        }

@@ -333,16 +334,23 @@ PHP_FUNCTION(count)
 #ifdef HAVE_SPL
                        /* if not and the object implements Countable we call its count() method */
                        if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) {
-                               zval *mode_zv;
-                               MAKE_STD_ZVAL(mode_zv);
-                               ZVAL_LONG(mode_zv, mode);
-                               zend_call_method_with_1_params(&array, NULL, NULL, "count", &retval, mode_zv);
+                               zval *mode_zv = NULL;
+
+                               if (argc > 1) {
+                                       MAKE_STD_ZVAL(mode_zv);
+                                       ZVAL_LONG(mode_zv, mode);
+                                       zend_call_method_with_1_params(&array, NULL, NULL, "count", &retval, mode_zv);
+                               } else {
+                                       zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval);
+                               }
                                if (retval) {
                                        convert_to_long_ex(&retval);
                                        RETVAL_LONG(Z_LVAL_P(retval));
                                        zval_ptr_dtor(&retval);
                                }
-                               zval_ptr_dtor(&mode_zv);
+                               if (mode_zv) {
+                                       zval_ptr_dtor(&mode_zv);
+                               }
                                return;
                        }
 #endif
diff --git a/ext/standard/tests/array/bug67064.phpt b/ext/standard/tests/array/bug67064.phpt
index 2818516..3d58bef 100644
--- a/ext/standard/tests/array/bug67064.phpt
+++ b/ext/standard/tests/array/bug67064.phpt
@@ -5,13 +5,23 @@ Bug #67064 (Countable interface prevents using 2nd parameter ($mode) of count()
 class Counter implements Countable {
        public function count($mode = COUNT_NORMAL) {
                var_dump($mode == COUNT_RECURSIVE);
+               var_dump(count(func_get_args()) == 1);
                return 1;
        }
 }

 $counter = new Counter;
+var_dump(count($counter));
+var_dump(count($counter, COUNT_NORMAL));
 var_dump(count($counter, COUNT_RECURSIVE));
 ?>
 --EXPECTF--
+bool(false)
+bool(false)
+int(1)
+bool(false)
+bool(true)
+int(1)
+bool(true)
 bool(true)
 int(1)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC