diff options
-rw-r--r-- | ext/standard/array.c | 35 | ||||
-rw-r--r-- | ext/standard/php_array.h | 13 |
2 files changed, 30 insertions, 18 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 218bbfb7f5..de3016332a 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -95,12 +95,32 @@ php_array_globals array_globals; #define DOUBLE_DRIFT_FIX 0.000000000000001 -PHP_MINIT_FUNCTION(array) -{ +ZEND_BEGIN_MODULE_GLOBALS(array) + int *multisort_flags[2]; + int (*compare_func)(zval *result, zval *op1, zval *op2 TSRMLS_DC); + zend_class_entry *php_ce_countable; +ZEND_END_MODULE_GLOBALS(array) + +ZEND_DECLARE_MODULE_GLOBALS(array) + #ifdef ZTS - ts_allocate_id(&array_globals_id, sizeof(php_array_globals), NULL, NULL); +#define ARRAYG(v) TSRMG(array_globals_id, zend_array_globals *, v) +#else +#define ARRAYG(v) (array_globals.v) #endif +/* {{{ php_extname_init_globals + */ +static void php_array_init_globals(zend_array_globals *array_globals) +{ + memset(array_globals, 0, sizeof(array_globals)); +} +/* }}} */ + +PHP_MINIT_FUNCTION(array) +{ + ZEND_INIT_MODULE_GLOBALS(array, php_array_init_globals, NULL); + REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", EXTR_OVERWRITE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EXTR_SKIP", EXTR_SKIP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("EXTR_PREFIX_SAME", EXTR_PREFIX_SAME, CONST_CS | CONST_PERSISTENT); @@ -304,10 +324,15 @@ PHP_FUNCTION(count) break; case IS_OBJECT: { #if HAVE_SPL - zend_class_entry **pce = NULL; zval *retval; + zend_class_entry **pce; - if (zend_lookup_class("countable", sizeof("countable")-1, &pce TSRMLS_CC) == SUCCESS) { + if (!ARRAYG(php_ce_countable)) { + if (zend_lookup_class("countable", sizeof("countable")-1, &pce TSRMLS_CC) == SUCCESS) { + ARRAYG(php_ce_countable) = *pce; + } + } + if (ARRAYG(php_ce_countable) && instanceof_function(Z_OBJCE_P(array), ARRAYG(php_ce_countable) TSRMLS_CC)) { zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval); RETVAL_LONG(Z_LVAL_P(retval)); zval_ptr_dtor(&retval); diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index 077862c5c3..46bd2c77dd 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -102,17 +102,4 @@ HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC); int multisort_compare(const void *a, const void *b TSRMLS_DC); -typedef struct { - int *multisort_flags[2]; - int (*compare_func)(zval *result, zval *op1, zval *op2 TSRMLS_DC); -} php_array_globals; - -#ifdef ZTS -#define ARRAYG(v) TSRMG(array_globals_id, php_array_globals *, v) -extern int array_globals_id; -#else -#define ARRAYG(v) (array_globals.v) -extern php_array_globals array_globals; -#endif - #endif /* PHP_ARRAY_H */ |