Skip to content

Commit cb9785a

Browse files
committed
Fixed bug #80723
This fixes the issue just for the Socket class. Presumably we'll want to do the same for other "resource" objects.
1 parent 2dc75a9 commit cb9785a

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ PHP NEWS
3535
. Fixed bug #70091 (Phar does not mark UTF-8 filenames in ZIP archives). (cmb)
3636
. Fixed bug #53467 (Phar cannot compress large archives). (cmb, lserni)
3737

38+
- Socket:
39+
. Fixed bug #80723 (Different sockets compare as equal (regression in 8.0)).
40+
(Nikita)
41+
3842
- SPL:
3943
. Fixed bug#80719 (Iterating after failed ArrayObject::setIteratorClass()
4044
causes Segmentation fault). (Nikita)

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
@@ -213,6 +213,10 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2);
213213
ZEND_API int zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, zend_bool check_only);
214214
ZEND_API void rebuild_object_properties(zend_object *zobj);
215215

216+
/* Handler for objects that cannot be meaningfully compared.
217+
* Only objects with the same identity will be considered equal. */
218+
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2);
219+
216220
ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope);
217221

218222
ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_info_name, zend_bool is_dynamic);

ext/sockets/sockets.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ static PHP_MINIT_FUNCTION(sockets)
446446
socket_object_handlers.get_constructor = socket_get_constructor;
447447
socket_object_handlers.clone_obj = NULL;
448448
socket_object_handlers.get_gc = socket_get_gc;
449+
socket_object_handlers.compare = zend_objects_not_comparable;
449450

450451
zend_class_entry ce_address_info;
451452
INIT_CLASS_ENTRY(ce_address_info, "AddressInfo", class_AddressInfo_methods);

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)