|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-13 03:16 UTC] ramsey@php.net
Description: ------------ I'm using the embed SAPI, and I came across an issue when using zend_hash_compare(). I wanted to use the provided hash_zval_compare_function() as the callback function for the compar parameter. However, I cannot use this, since it is not exposed. I could use zend_compare_arrays(), but it doesn't allow me to pass in a 1 as the value of the ordered parameter sent to zend_hash_compare(). Since I want to compare arrays like comparing with the identity operator, then I need to use zend_hash_compare() and create my own callback that does exactly what hash_zval_compare_function() does, thus reinventing the wheel. Either: 1) Expose hash_zval_compare_function() so it can be used by third-party apps - or - 2) Make a second version of zend_compare_arrays() that allows you to compare arrays by identity (i.e. zend_compare_arrays_identity()?) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 00:00:02 2025 UTC |
Patch for zend_compare_arrays_identity(): Index: Zend/zend_operators.c =================================================================== --- Zend/zend_operators.c (revision 287194) +++ Zend/zend_operators.c (working copy) @@ -2011,12 +2011,24 @@ } /* }}} */ +ZEND_API void zend_compare_symbol_tables_identity(zval *result, HashTable *ht1, HashTable *ht2 TSRMLS_DC) /* {{{ */ +{ + ZVAL_LONG(result, zend_hash_compare(ht1, ht2, (compare_func_t) hash_zval_compare_function, 1 TSRMLS_CC)); +} +/* }}} */ + ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC) /* {{{ */ { zend_compare_symbol_tables(result, Z_ARRVAL_P(a1), Z_ARRVAL_P(a2) TSRMLS_CC); } /* }}} */ +ZEND_API void zend_compare_arrays_identity(zval *result, zval *a1, zval *a2 TSRMLS_DC) /* {{{ */ +{ + zend_compare_symbol_tables_identity(result, Z_ARRVAL_P(a1), Z_ARRVAL_P(a2) TSRMLS_CC); +} +/* }}} */ + ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC) /* {{{ */ { Z_TYPE_P(result) = IS_LONG; Index: Zend/zend_operators.h =================================================================== --- Zend/zend_operators.h (revision 287194) +++ Zend/zend_operators.h (working copy) @@ -319,6 +319,7 @@ ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2); ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2 TSRMLS_DC); ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2 TSRMLS_DC); +ZEND_API void zend_compare_arrays_identity(zval *result, zval *a1, zval *a2 TSRMLS_DC); ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2 TSRMLS_DC); ZEND_API int zend_atoi(const char *str, int str_len);