php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49242 Expose function in Zend API for comparing arrays by identity
Submitted: 2009-08-13 03:16 UTC Modified: 2009-08-21 01:00 UTC
From: ramsey@php.net Assigned:
Status: No Feedback Package: Feature/Change Request
PHP Version: 5.3SVN-2009-08-13 (SVN) OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ramsey@php.net
New email:
PHP Version: OS:

 

 [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()?)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-13 03:18 UTC] ramsey@php.net
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);
 [2009-08-13 08:50 UTC] derick@php.net
Could you post a link to the patch perhaps? It got mangled up in here.
 [2009-08-13 15:23 UTC] ramsey@php.net
Here you go: http://pastie.org/pastes/582230
 [2009-08-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 03:01:32 2025 UTC