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
14 changes: 12 additions & 2 deletions ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ static zval *sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, z
goto long_dim;
} else {
ZVAL_DEREF(member);
if (Z_TYPE_P(member) == IS_LONG) {
if (Z_TYPE_P(member) == IS_LONG || Z_TYPE_P(member) == IS_DOUBLE) {
if (Z_TYPE_P(member) == IS_DOUBLE) {
ZVAL_LONG(&tmp_zv, (long) Z_DVAL_P(member));
member = &tmp_zv;
}

if (sxe->iter.type != SXE_ITER_ATTRLIST) {
long_dim:
attribs = 0;
Expand Down Expand Up @@ -447,7 +452,12 @@ static int sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool
goto long_dim;
} else {
ZVAL_DEREF(member);
if (Z_TYPE_P(member) == IS_LONG) {
if (Z_TYPE_P(member) == IS_LONG || Z_TYPE_P(member) == IS_DOUBLE) {
if (Z_TYPE_P(member) == IS_DOUBLE) {
ZVAL_LONG(&tmp_zv, (long) Z_DVAL_P(member));
member = &tmp_zv;
}

if (sxe->iter.type != SXE_ITER_ATTRLIST) {
long_dim:
attribs = 0;
Expand Down
19 changes: 19 additions & 0 deletions ext/simplexml/tests/bug61877.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug #61597: SimpleXMLElement does not respect PHP's array keys cast rule
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
?>
--FILE--
<?php
$simpleXMLElement = simplexml_load_string("<xml><number>0</number><number>1</number></xml>");

$int = 1;
$float = 1.0;

$simpleXMLElement->number[$float] = 999;

echo $simpleXMLElement->number[$float] . ', ' . $simpleXMLElement->number[$int];
?>
--EXPECT--
999, 999