summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorEtienne Kneuss <colder@php.net>2009-01-14 15:53:03 +0000
committerEtienne Kneuss <colder@php.net>2009-01-14 15:53:03 +0000
commitcd63e52c0b438f514496404c25f6eb971601555d (patch)
treee5ae3d61b262a654d919ef8d8213fba364c8c7df /ext/spl
parent582b32c426ea5d6f74563e9d3d37202d426b7ad4 (diff)
downloadphp-git-cd63e52c0b438f514496404c25f6eb971601555d.tar.gz
MFH: Fix #47045 (Correctly compare splobjectstorages with ==)
Diffstat (limited to 'ext/spl')
-rwxr-xr-xext/spl/spl_observer.c29
-rw-r--r--ext/spl/tests/observer_007.phpt22
2 files changed, 50 insertions, 1 deletions
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 0f60502b00..5b0eb71b69 100755
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -169,6 +169,31 @@ static HashTable* spl_object_storage_debug_info(zval *obj, int *is_temp TSRMLS_D
}
/* }}} */
+static int spl_object_storage_compare_info(spl_SplObjectStorageElement *e1, spl_SplObjectStorageElement *e2 TSRMLS_DC) /* {{{ */
+{
+ zval result;
+
+ if (compare_function(&result, e1->inf, e2->inf TSRMLS_CC) == FAILURE) {
+ return 1;
+ }
+
+ return Z_LVAL(result);
+}
+/* }}} */
+
+static int spl_object_storage_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
+{
+ zend_object *zo1 = (zend_object *)zend_object_store_get_object(o1 TSRMLS_CC);
+ zend_object *zo2 = (zend_object *)zend_object_store_get_object(o2 TSRMLS_CC);
+
+ if (zo1->ce != spl_ce_SplObjectStorage || zo2->ce != spl_ce_SplObjectStorage) {
+ return 1;
+ }
+
+ return zend_hash_compare(&((spl_SplObjectStorage *)zo1)->storage, &((spl_SplObjectStorage *)zo2)->storage, (compare_func_t) spl_object_storage_compare_info, 0 TSRMLS_CC);
+}
+/* }}} */
+
/* {{{ spl_array_object_new */
static zend_object_value spl_SplObjectStorage_new(zend_class_entry *class_type TSRMLS_DC)
{
@@ -910,7 +935,9 @@ PHP_MINIT_FUNCTION(spl_observer)
REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_info;
+
+ spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_info;
+ spl_handler_SplObjectStorage.compare_objects = spl_object_storage_compare_objects;
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable);
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator);
diff --git a/ext/spl/tests/observer_007.phpt b/ext/spl/tests/observer_007.phpt
new file mode 100644
index 0000000000..e494f19796
--- /dev/null
+++ b/ext/spl/tests/observer_007.phpt
@@ -0,0 +1,22 @@
+--TEST--
+SPL: SplObjectStorage comapred with ==
+--FILE--
+<?php
+$a = new SplObjectStorage;
+$b = new SplObjectStorage;
+var_dump($a == $b);
+$b[$b] = 2;
+var_dump($a == $b);
+$a[$b] = 2;
+var_dump($a == $b);
+$a[$b] = 3;
+var_dump($a == $b);
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+===DONE===