Skip to content

Commit 1f04f16

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fixed bug #80723
2 parents 2fe6df7 + cb9785a commit 1f04f16

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

Zend/zend_object_handlers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,11 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
16081608
}
16091609
/* }}} */
16101610

1611+
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
1612+
{
1613+
return ZEND_UNCOMPARABLE;
1614+
}
1615+
16111616
ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) /* {{{ */
16121617
{
16131618
int result;

Zend/zend_object_handlers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2);
225225
ZEND_API int zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only);
226226
ZEND_API void rebuild_object_properties(zend_object *zobj);
227227

228+
/* Handler for objects that cannot be meaningfully compared.
229+
* Only objects with the same identity will be considered equal. */
230+
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2);
231+
228232
ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope);
229233

230234
ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_info_name, bool is_dynamic);

ext/sockets/sockets.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ static PHP_MINIT_FUNCTION(sockets)
443443
socket_object_handlers.get_constructor = socket_get_constructor;
444444
socket_object_handlers.clone_obj = NULL;
445445
socket_object_handlers.get_gc = socket_get_gc;
446+
socket_object_handlers.compare = zend_objects_not_comparable;
446447

447448
address_info_ce = register_class_AddressInfo();
448449
address_info_ce->create_object = address_info_create_object;

ext/sockets/tests/bug80723.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #80723: Different sockets compare as equal (regression in 8.0)
3+
--FILE--
4+
<?php
5+
$socket_1 = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
6+
$socket_2 = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
7+
var_dump($socket_1 == $socket_1);
8+
var_dump($socket_2 == $socket_2);
9+
var_dump($socket_1 == $socket_2);
10+
11+
$vector = array(1 => $socket_1, 2 => $socket_2);
12+
var_dump(array_search($socket_1, $vector));
13+
var_dump(array_search($socket_2, $vector));
14+
15+
?>
16+
--EXPECT--
17+
bool(true)
18+
bool(true)
19+
bool(false)
20+
int(1)
21+
int(2)

0 commit comments

Comments
 (0)