Skip to content

Commit 6bf483a

Browse files
committed
Clarify SimpleXML comparison logic
1 parent fb5bfcb commit 6bf483a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ext/simplexml/simplexml.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,16 +1291,24 @@ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
12911291
sxe1 = Z_SXEOBJ_P(object1);
12921292
sxe2 = Z_SXEOBJ_P(object2);
12931293

1294-
if (sxe1->node == NULL) {
1295-
if (sxe2->node) {
1296-
return 1;
1297-
} else if (sxe1->document->ptr == sxe2->document->ptr) {
1294+
if (sxe1->node != NULL && sxe2->node != NULL) {
1295+
/* Both nodes set: Only support equality comparison between nodes. */
1296+
if (sxe1->node == sxe2->node) {
12981297
return 0;
12991298
}
1300-
return 1;
1301-
} else {
1302-
return !(sxe1->node == sxe2->node);
1299+
return ZEND_UNCOMPARABLE;
13031300
}
1301+
1302+
if (sxe1->node == NULL && sxe2->node == NULL) {
1303+
/* Both nodes not set: Only support equality comparison between documents. */
1304+
if (sxe1->document->ptr == sxe2->document->ptr) {
1305+
return 0;
1306+
}
1307+
return ZEND_UNCOMPARABLE;
1308+
}
1309+
1310+
/* Only one of the nodes set: Cannot compare. */
1311+
return ZEND_UNCOMPARABLE;
13041312
}
13051313
/* }}} */
13061314

0 commit comments

Comments
 (0)