summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorEtienne Kneuss <colder@php.net>2008-07-09 21:29:52 +0000
committerEtienne Kneuss <colder@php.net>2008-07-09 21:29:52 +0000
commit8ceb0b6fd36b4a228a15d97ec01361589d4834da (patch)
treee737cf51379cc76a3c5506f6831963a638ccbccf /ext/standard/array.c
parent003841e312c00966846c636a3d9b2f41915ae297 (diff)
downloadphp-git-8ceb0b6fd36b4a228a15d97ec01361589d4834da.tar.gz
MFH: Fix resolution rule of count vs. handler
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 3e69d9573a..5f35c66121 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -319,9 +319,17 @@ PHP_FUNCTION(count)
break;
case IS_OBJECT: {
#ifdef HAVE_SPL
- /* it the object implements Countable we call its count() method */
zval *retval;
-
+#endif
+ /* first, we check if the handler is defined */
+ if (Z_OBJ_HT_P(array)->count_elements) {
+ RETVAL_LONG(1);
+ if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value) TSRMLS_CC)) {
+ return;
+ }
+ }
+#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)) {
zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval);
if (retval) {
@@ -332,13 +340,6 @@ PHP_FUNCTION(count)
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);
- if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value) TSRMLS_CC)) {
- return;
- }
- }
}
default:
RETURN_LONG(1);