Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,12 +1843,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
sxe = php_sxe_fetch_object(readobj);

if (type == _IS_BOOL) {
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
if (node) {
ZVAL_TRUE(writeobj);
} else {
ZVAL_BOOL(writeobj, !sxe_prop_is_empty(readobj));
}
ZVAL_BOOL(writeobj, !sxe_prop_is_empty(readobj));
return SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/simplexml/tests/000.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object(SimpleXMLElement)#%d (1) {
}
===sxe->elem11->elem111->elem1111
bool(true)
bool(true)
bool(false)
int(1)
object(SimpleXMLElement)#%d (0) {
}
Expand Down
18 changes: 18 additions & 0 deletions ext/simplexml/tests/gh21583.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-21583 (SimpleXML empty element incorrectly casts to true)
--EXTENSIONS--
simplexml
--FILE--
<?php
$xml = new SimpleXMLElement('<foo><bar/><baz attr="val"/><qux>text</qux></foo>');

var_dump((bool) $xml->bar);
var_dump((bool) $xml->baz);
var_dump((bool) $xml->qux);
var_dump((bool) $xml->nonexistent);
?>
--EXPECT--
bool(false)
bool(true)
bool(true)
bool(false)
Loading