Skip to content

Commit e8217a2

Browse files
committed
Fix bug #69891
1 parent 5bf7a3a commit e8217a2

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP NEWS
2424
(Christian Wenz)
2525
. Fixed bug #69889 (Null coalesce operator doesn't work for string offsets).
2626
(Nikita)
27+
. Fixed bug #69891 (Unexpected array comparison result). (Nikita)
2728
. Fixed bug #69892 (Different arrays compare indentical due to integer key
2829
truncation). (Nikita)
2930
. Fixed bug #69893 (Strict comparison between integer and empty string keys

Zend/tests/bug69891.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #69891: Unexpected array comparison result
3+
--FILE--
4+
<?php
5+
6+
var_dump([1, 2, 3] <=> []);
7+
var_dump([] <=> [1, 2, 3]);
8+
var_dump([1] <=> [2, 3]);
9+
--EXPECT--
10+
int(1)
11+
int(-1)
12+
int(-1)

Zend/tests/bug69893.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Bug #69893: Strict comparison between integer and empty string keys crashes
3+
--FILE--
4+
<?php
5+
var_dump([0 => 0] === ["" => 0]);
6+
?>
7+
--EXPECT--
8+
bool(false)

Zend/zend_hash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,11 +2220,10 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t co
22202220
HASH_PROTECT_RECURSION(ht1);
22212221
HASH_PROTECT_RECURSION(ht2);
22222222

2223-
result = ht1->nNumOfElements - ht2->nNumOfElements;
2224-
if (result!=0) {
2223+
if (ht1->nNumOfElements != ht2->nNumOfElements) {
22252224
HASH_UNPROTECT_RECURSION(ht1);
22262225
HASH_UNPROTECT_RECURSION(ht2);
2227-
return result;
2226+
return ht1->nNumOfElements > ht2->nNumOfElements ? 1 : -1;
22282227
}
22292228

22302229
for (idx1 = 0, idx2 = 0; idx1 < ht1->nNumUsed; idx1++) {

0 commit comments

Comments
 (0)