From d6790c6a4780cbbb795851a3e561c94caa256bfc Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 12 Feb 2007 19:34:58 +0000 Subject: Fix regression: count(object) should call object->count() if instance of Countable. Spotted by: Roman Neuhauser --- lang/php5/Makefile | 2 +- lang/php5/files/patch-ext_standard_array.c | 33 +++++++++++++++++++++++++++++ lang/php53/Makefile | 2 +- lang/php53/files/patch-ext_standard_array.c | 33 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 lang/php5/files/patch-ext_standard_array.c create mode 100644 lang/php53/files/patch-ext_standard_array.c (limited to 'lang') diff --git a/lang/php5/Makefile b/lang/php5/Makefile index e9d98ee984dc..cfeed28af2ef 100644 --- a/lang/php5/Makefile +++ b/lang/php5/Makefile @@ -7,7 +7,7 @@ PORTNAME= php5 PORTVERSION= 5.2.1 -PORTREVISION?= 0 +PORTREVISION?= 1 CATEGORIES?= lang devel www MASTER_SITES= ${MASTER_SITE_PHP:S,$,:release,} \ http://downloads.php.net/ilia/:rc \ diff --git a/lang/php5/files/patch-ext_standard_array.c b/lang/php5/files/patch-ext_standard_array.c new file mode 100644 index 000000000000..bd6d4d0c95d4 --- /dev/null +++ b/lang/php5/files/patch-ext_standard_array.c @@ -0,0 +1,33 @@ +--- ext/standard/array.c.orig Mon Feb 12 20:20:48 2007 ++++ ext/standard/array.c Mon Feb 12 20:22:14 2007 +@@ -295,6 +295,7 @@ + PHP_FUNCTION(count) + { + zval *array; ++ zend_class_entry **ce_Countable; + long mode = COUNT_NORMAL; + + if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE) +@@ -308,11 +309,11 @@ + RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC)); + break; + case IS_OBJECT: { +-#ifdef HAVE_SPL + /* it the object implements Countable we call its count() method */ + zval *retval; + +- if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) { ++ if (zend_lookup_class_ex("Countable", 9, 0, &ce_Countable TSRMLS_CC) != FAILURE) { ++ if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), *ce_Countable TSRMLS_CC)) { + zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); + if (retval) { + convert_to_long(retval); +@@ -321,7 +322,7 @@ + } + return; + } +-#endif ++ } + /* if not we return the number of properties (not taking visibility into account) */ + if (Z_OBJ_HT_P(array)->count_elements) { + RETVAL_LONG(1); diff --git a/lang/php53/Makefile b/lang/php53/Makefile index e9d98ee984dc..cfeed28af2ef 100644 --- a/lang/php53/Makefile +++ b/lang/php53/Makefile @@ -7,7 +7,7 @@ PORTNAME= php5 PORTVERSION= 5.2.1 -PORTREVISION?= 0 +PORTREVISION?= 1 CATEGORIES?= lang devel www MASTER_SITES= ${MASTER_SITE_PHP:S,$,:release,} \ http://downloads.php.net/ilia/:rc \ diff --git a/lang/php53/files/patch-ext_standard_array.c b/lang/php53/files/patch-ext_standard_array.c new file mode 100644 index 000000000000..bd6d4d0c95d4 --- /dev/null +++ b/lang/php53/files/patch-ext_standard_array.c @@ -0,0 +1,33 @@ +--- ext/standard/array.c.orig Mon Feb 12 20:20:48 2007 ++++ ext/standard/array.c Mon Feb 12 20:22:14 2007 +@@ -295,6 +295,7 @@ + PHP_FUNCTION(count) + { + zval *array; ++ zend_class_entry **ce_Countable; + long mode = COUNT_NORMAL; + + if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE) +@@ -308,11 +309,11 @@ + RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC)); + break; + case IS_OBJECT: { +-#ifdef HAVE_SPL + /* it the object implements Countable we call its count() method */ + zval *retval; + +- if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) { ++ if (zend_lookup_class_ex("Countable", 9, 0, &ce_Countable TSRMLS_CC) != FAILURE) { ++ if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), *ce_Countable TSRMLS_CC)) { + zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); + if (retval) { + convert_to_long(retval); +@@ -321,7 +322,7 @@ + } + return; + } +-#endif ++ } + /* if not we return the number of properties (not taking visibility into account) */ + if (Z_OBJ_HT_P(array)->count_elements) { + RETVAL_LONG(1); -- cgit