Skip to content

Commit 5f9e78f

Browse files
committed
Address code review
1 parent e050b24 commit 5f9e78f

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

ext/simplexml/simplexml.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
432432
* and could also be E_PARSE, but we use this only during parsing
433433
* and this is during runtime.
434434
*/
435-
zend_throw_error(NULL, "Cannot create unnamed attribute");
435+
zend_throw_error(NULL, "Cannot append to an attribute list");
436436
return &EG(error_zval);
437437
}
438438
goto long_dim;
@@ -457,7 +457,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
457457
}
458458

459459
if (!Z_STRLEN_P(member)) {
460-
zend_value_error("Cannot create or write %s with an empty name", attribs ? "attributes" : "elements");
460+
zend_value_error("Cannot create %s with an empty name", attribs ? "attributes" : "elements");
461461
if (member == &tmp_zv) {
462462
zval_ptr_dtor_str(&tmp_zv);
463463
}
@@ -485,7 +485,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
485485
* and could also be E_PARSE, but we use this only during parsing
486486
* and this is during runtime.
487487
*/
488-
zend_value_error("Cannot create or write attributes with an empty name");
488+
zend_value_error("Cannot append to an attribute list");
489489
return &EG(error_zval);
490490
}
491491
if (attribs && !node && sxe->iter.type == SXE_ITER_ELEMENT) {
@@ -514,8 +514,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
514514
case IS_OBJECT:
515515
if (Z_OBJCE_P(value) == sxe_class_entry) {
516516
if (sxe_object_cast_ex(Z_OBJ_P(value), &zval_copy, IS_STRING) == FAILURE) {
517-
zend_error(E_ERROR, "Unable to cast node to string");
518-
/* FIXME: Should not be fatal */
517+
zend_throw_error(NULL, "Unable to cast node to string");
519518
}
520519

521520
value = &zval_copy;

ext/simplexml/simplexml.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function rewind() {}
5959
/** @return bool */
6060
public function valid() {}
6161

62-
/** @return ?SimpleXMLElement */
62+
/** @return SimpleXMLElement|null */
6363
public function current() {}
6464

6565
/** @return string|false */
@@ -71,7 +71,7 @@ public function next() {}
7171
/** @return bool */
7272
public function hasChildren() {}
7373

74-
/** @return ?SimpleXMLElement */
74+
/** @return SimpleXMLElement|null */
7575
public function getChildren() {}
7676
}
7777

ext/simplexml/simplexml_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: fbe25d8a7a0a1de0cbd5dc9118e77a2e8d5dbd67 */
2+
* Stub hash: 953089f230247acf18b9ac48c0a4c516d144a987 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_file, 0, 1, SimpleXMLElement, MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)

ext/simplexml/tests/012.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ EOF;
1515
$sxe = simplexml_load_string($xml);
1616

1717
try {
18-
$sxe[""] = "warning";
18+
$sxe[""] = "value";
1919
} catch (ValueError $exception) {
2020
echo $exception->getMessage() . "\n";
2121
}
@@ -38,9 +38,9 @@ __HALT_COMPILER();
3838
?>
3939
===DONE===
4040
--EXPECT--
41-
Cannot create or write attributes with an empty name
41+
Cannot create attributes with an empty name
4242
<?xml version="1.0" encoding="ISO-8859-1"?>
4343
<foo attr="value"/>
4444
<?xml version="1.0" encoding="ISO-8859-1"?>
4545
<foo attr="new value"/>
46-
Cannot create or write attributes with an empty name
46+
Cannot append to an attribute list

ext/simplexml/tests/bug37076_1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ try {
1616
print $xml->asXML();
1717
?>
1818
--EXPECT--
19-
Cannot create or write elements with an empty name
19+
Cannot create elements with an empty name
2020
<?xml version="1.0"?>
2121
<root><foo/></root>

ext/simplexml/tests/complex_node.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Test that it's not possible to assign a complex type to nodes
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
$xml = simplexml_load_string(<<<EOF
9+
<?xml version="1.0"?>
10+
<root>
11+
<child>Hello</child>
12+
</root>
13+
EOF);
14+
15+
try {
16+
$xml->child = new stdClass();
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
21+
?>
22+
--EXPECT--
23+
It's not possible to assign a complex type to nodes, array given

0 commit comments

Comments
 (0)