]> granicus.if.org Git - php/commitdiff
- Fix bug introduced in earlier patch
authorDerick Rethans <derick@php.net>
Wed, 9 Jan 2002 16:03:36 +0000 (16:03 +0000)
committerDerick Rethans <derick@php.net>
Wed, 9 Jan 2002 16:03:36 +0000 (16:03 +0000)
ext/standard/array.c
ext/standard/tests/array/count_recursive.phpt

index 3ce6d17cc03273d0d0fefc0b4584f9767bc8ab59..86331a75e8ac90e75682f64813e88d3d0ea9938c 100644 (file)
@@ -260,11 +260,16 @@ PHP_FUNCTION(count)
        if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE)
                return;
        
-       if (Z_TYPE_P(array) == IS_ARRAY) {
-               RETURN_LONG (php_count_recursive (array, mode));
-       } else {
-               /* return 1 for non-array arguments */
-               RETURN_LONG(1);
+       switch (Z_TYPE_P(array)) {
+               case IS_NULL:
+                       RETURN_LONG(0);
+                       break;
+               case IS_ARRAY:
+                       RETURN_LONG (php_count_recursive (array, mode));
+                       break;
+               default:
+                       RETURN_LONG(1);
+                       break;
        }
 }
 /* }}} */
index 6e7d141d817e684494386762199fe7b7af757a7c..a6b7ee4afa6923262dd4d75d86dfd9d59941415a 100644 (file)
@@ -4,6 +4,11 @@ count
 --GET--
 --FILE--
 <?php
+print "Testing NULL...\n";
+$arr = NULL;
+print "COUNT_NORMAL: should be 0, is ".count($arr, COUNT_NORMAL)."\n";
+print "COUNT_RECURSIVE: should be 0, is ".count($arr, COUNT_RECURSIVE)."\n";
+
 print "Testing arrays...\n";
 $arr = array(1, array(3, 4, array(6, array(8))));
 print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n";
@@ -23,6 +28,9 @@ print "COUNT_NORMAL: should be 1, is ".count("string")."\n";
 print "COUNT_NORMAL: should be 2, is ".count(array("a", array("b")))."\n";
 ?>
 --EXPECT--
+Testing NULL...
+COUNT_NORMAL: should be 0, is 0
+COUNT_RECURSIVE: should be 0, is 0
 Testing arrays...
 COUNT_NORMAL: should be 2, is 2
 COUNT_RECURSIVE: should be 8, is 8