Skip to content

Commit 7bbf5fe

Browse files
committed
- Fixed bug #61326 (ArrayObject comparison).
1 parent b39ffa3 commit 7bbf5fe

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

NEWS

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ PHP NEWS
4747
. Fixed bug #61267 (pdo_pgsql's PDO::exec() returns the number of SELECTed
4848
rows on postgresql >= 9). (ben dot pineau at gmail dot com)
4949

50+
- PDO_Sqlite extension:
51+
. Add createCollation support. (Damien)
52+
5053
- Phar:
5154
. Fixed bug #61184 (Phar::webPhar() generates headers with trailing NUL
5255
bytes). (Nikic)
@@ -60,13 +63,13 @@ PHP NEWS
6063
chunksize length line is > 10 bytes). (Ilia)
6164
. Fixed bug #60887 (SoapClient ignores user_agent option and sends no
6265
User-Agent header). (carloschilazo at gmail dot com)
63-
66+
67+
- SPL
68+
. Fixed bug #61326 (ArrayObject comparison). (Gustavo)
69+
6470
- SQLite3 extension:
6571
. Add createCollation() method. (Brad Dewar)
6672

67-
- PDO_Sqlite extension:
68-
. Add createCollation support. (Damien)
69-
7073
- Reflection:
7174
. Fixed bug #60968 (Late static binding doesn't work with
7275
ReflectionMethod::invokeArgs()). (Laruence)

ext/spl/spl_array.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,30 @@ static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{
836836
std_object_handlers.unset_property(object, member TSRMLS_CC);
837837
} /* }}} */
838838

839+
static int spl_array_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
840+
{
841+
HashTable *ht1,
842+
*ht2;
843+
spl_array_object *intern1,
844+
*intern2;
845+
int result = 0;
846+
zval temp_zv;
847+
848+
intern1 = (spl_array_object*)zend_object_store_get_object(o1 TSRMLS_CC);
849+
intern2 = (spl_array_object*)zend_object_store_get_object(o2 TSRMLS_CC);
850+
ht1 = spl_array_get_hash_table(intern1, 0 TSRMLS_CC);
851+
ht2 = spl_array_get_hash_table(intern2, 0 TSRMLS_CC);
852+
853+
zend_compare_symbol_tables(&temp_zv, ht1, ht2 TSRMLS_CC);
854+
result = (int)Z_LVAL(temp_zv);
855+
/* if we just compared std.properties, don't do it again */
856+
if (result == 0 &&
857+
!(ht1 == intern1->std.properties && ht2 == intern2->std.properties)) {
858+
result = std_object_handlers.compare_objects(o1, o2 TSRMLS_CC);
859+
}
860+
return result;
861+
} /* }}} */
862+
839863
static int spl_array_skip_protected(spl_array_object *intern, HashTable *aht TSRMLS_DC) /* {{{ */
840864
{
841865
char *string_key;
@@ -2003,6 +2027,8 @@ PHP_MINIT_FUNCTION(spl_array)
20032027
spl_handler_ArrayObject.has_property = spl_array_has_property;
20042028
spl_handler_ArrayObject.unset_property = spl_array_unset_property;
20052029

2030+
spl_handler_ArrayObject.compare_objects = spl_array_compare_objects;
2031+
20062032
REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new, spl_funcs_ArrayIterator);
20072033
REGISTER_SPL_IMPLEMENTS(ArrayIterator, Iterator);
20082034
REGISTER_SPL_IMPLEMENTS(ArrayIterator, ArrayAccess);

ext/spl/tests/bug61326.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #61326: ArrayObject comparison
3+
--FILE--
4+
<?php
5+
$aobj1 = new ArrayObject(array(0));
6+
$aobj2 = new ArrayObject(array(1));
7+
var_dump($aobj1 == $aobj2);
8+
9+
$aobj3 = new ArrayObject(array(0));
10+
var_dump($aobj1 == $aobj3);
11+
12+
$aobj3->foo = 'bar';
13+
var_dump($aobj1 == $aobj3);
14+
--EXPECT--
15+
bool(false)
16+
bool(true)
17+
bool(false)

0 commit comments

Comments
 (0)