mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-15123: var_dump doesn't actually work on XMLReader (#15130)
This commit is contained in:
4
NEWS
4
NEWS
@@ -64,6 +64,10 @@ PHP NEWS
|
||||
. Add tidyNode::getNextSibling() and tidyNode::getPreviousSibling().
|
||||
(nielsdos)
|
||||
|
||||
- XMLReader:
|
||||
. Fixed bug GH-15123 (var_dump doesn't actually work on XMLReader).
|
||||
(nielsdos)
|
||||
|
||||
- XSL:
|
||||
. Fix trampoline leak in xpath callables. (nielsdos)
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ static int xmlreader_property_reader(xmlreader_object *obj, xmlreader_prop_handl
|
||||
if (hnd->read_int_func) {
|
||||
retint = hnd->read_int_func(obj->ptr);
|
||||
if (retint == -1) {
|
||||
zend_throw_error(NULL, "Failed to read property due to libxml error");
|
||||
zend_throw_error(NULL, "Failed to read property because no XML data has been read yet");
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,28 @@ static zend_function *xmlreader_get_method(zend_object **obj, zend_string *name,
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static HashTable* xmlreader_get_debug_info(zend_object *object, int *is_temp)
|
||||
{
|
||||
*is_temp = 1;
|
||||
|
||||
xmlreader_object *obj = php_xmlreader_fetch_object(object);
|
||||
HashTable *std_props = zend_std_get_properties(object);
|
||||
HashTable *debug_info = zend_array_dup(std_props);
|
||||
|
||||
zend_string *string_key;
|
||||
xmlreader_prop_handler *entry;
|
||||
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&xmlreader_prop_handlers, string_key, entry) {
|
||||
ZEND_ASSERT(string_key != NULL);
|
||||
|
||||
zval value;
|
||||
if (xmlreader_property_reader(obj, entry, &value) == SUCCESS) {
|
||||
zend_hash_update(debug_info, string_key, &value);
|
||||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
|
||||
return debug_info;
|
||||
}
|
||||
|
||||
/* {{{ _xmlreader_get_valid_file_path */
|
||||
/* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a
|
||||
common function in libxml extension as code is common to a few xml extensions */
|
||||
@@ -1272,6 +1294,7 @@ PHP_MINIT_FUNCTION(xmlreader)
|
||||
xmlreader_object_handlers.get_property_ptr_ptr = xmlreader_get_property_ptr_ptr;
|
||||
xmlreader_object_handlers.get_method = xmlreader_get_method;
|
||||
xmlreader_object_handlers.clone_obj = NULL;
|
||||
xmlreader_object_handlers.get_debug_info = xmlreader_get_debug_info;
|
||||
|
||||
xmlreader_class_entry = register_class_XMLReader();
|
||||
xmlreader_class_entry->create_object = xmlreader_objects_new;
|
||||
|
||||
@@ -18,7 +18,11 @@ fwrite($h, "<root/>");
|
||||
fseek($h, 0);
|
||||
|
||||
$reader = CustomXMLReader::fromStream($h, encoding: "UTF-8");
|
||||
var_dump($reader);
|
||||
try {
|
||||
var_dump($reader);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
var_dump($reader->read());
|
||||
var_dump($reader->nodeType);
|
||||
|
||||
@@ -26,37 +30,36 @@ fclose($h);
|
||||
?>
|
||||
--EXPECTF--
|
||||
hello world
|
||||
object(CustomXMLReader)#%d (1) {
|
||||
["attributeCount"]=>
|
||||
uninitialized(int)
|
||||
["baseURI"]=>
|
||||
uninitialized(string)
|
||||
["depth"]=>
|
||||
uninitialized(int)
|
||||
["hasAttributes"]=>
|
||||
uninitialized(bool)
|
||||
["hasValue"]=>
|
||||
uninitialized(bool)
|
||||
["isDefault"]=>
|
||||
uninitialized(bool)
|
||||
["isEmptyElement"]=>
|
||||
uninitialized(bool)
|
||||
["localName"]=>
|
||||
uninitialized(string)
|
||||
["name"]=>
|
||||
uninitialized(string)
|
||||
["namespaceURI"]=>
|
||||
uninitialized(string)
|
||||
["nodeType"]=>
|
||||
uninitialized(int)
|
||||
["prefix"]=>
|
||||
uninitialized(string)
|
||||
["value"]=>
|
||||
uninitialized(string)
|
||||
["xmlLang"]=>
|
||||
uninitialized(string)
|
||||
object(CustomXMLReader)#%d (14) {
|
||||
["myField"]=>
|
||||
int(1234)
|
||||
["attributeCount"]=>
|
||||
int(0)
|
||||
["baseURI"]=>
|
||||
string(0) ""
|
||||
["depth"]=>
|
||||
int(0)
|
||||
["hasAttributes"]=>
|
||||
bool(false)
|
||||
["hasValue"]=>
|
||||
bool(false)
|
||||
["isDefault"]=>
|
||||
bool(false)
|
||||
["localName"]=>
|
||||
string(0) ""
|
||||
["name"]=>
|
||||
string(0) ""
|
||||
["namespaceURI"]=>
|
||||
string(0) ""
|
||||
["nodeType"]=>
|
||||
int(0)
|
||||
["prefix"]=>
|
||||
string(0) ""
|
||||
["value"]=>
|
||||
string(0) ""
|
||||
["xmlLang"]=>
|
||||
string(0) ""
|
||||
}
|
||||
Failed to read property because no XML data has been read yet
|
||||
bool(true)
|
||||
int(1)
|
||||
|
||||
@@ -14,43 +14,46 @@ class CustomXMLReader extends XMLReader {
|
||||
}
|
||||
|
||||
$reader = CustomXMLReader::fromString("<root/>");
|
||||
var_dump($reader);
|
||||
try {
|
||||
var_dump($reader);
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
var_dump($reader->read());
|
||||
var_dump($reader->nodeType);
|
||||
?>
|
||||
--EXPECTF--
|
||||
hello world
|
||||
object(CustomXMLReader)#%d (1) {
|
||||
["attributeCount"]=>
|
||||
uninitialized(int)
|
||||
["baseURI"]=>
|
||||
uninitialized(string)
|
||||
["depth"]=>
|
||||
uninitialized(int)
|
||||
["hasAttributes"]=>
|
||||
uninitialized(bool)
|
||||
["hasValue"]=>
|
||||
uninitialized(bool)
|
||||
["isDefault"]=>
|
||||
uninitialized(bool)
|
||||
["isEmptyElement"]=>
|
||||
uninitialized(bool)
|
||||
["localName"]=>
|
||||
uninitialized(string)
|
||||
["name"]=>
|
||||
uninitialized(string)
|
||||
["namespaceURI"]=>
|
||||
uninitialized(string)
|
||||
["nodeType"]=>
|
||||
uninitialized(int)
|
||||
["prefix"]=>
|
||||
uninitialized(string)
|
||||
["value"]=>
|
||||
uninitialized(string)
|
||||
["xmlLang"]=>
|
||||
uninitialized(string)
|
||||
object(CustomXMLReader)#%d (14) {
|
||||
["myField"]=>
|
||||
int(1234)
|
||||
["attributeCount"]=>
|
||||
int(0)
|
||||
["baseURI"]=>
|
||||
string(0) ""
|
||||
["depth"]=>
|
||||
int(0)
|
||||
["hasAttributes"]=>
|
||||
bool(false)
|
||||
["hasValue"]=>
|
||||
bool(false)
|
||||
["isDefault"]=>
|
||||
bool(false)
|
||||
["localName"]=>
|
||||
string(0) ""
|
||||
["name"]=>
|
||||
string(0) ""
|
||||
["namespaceURI"]=>
|
||||
string(0) ""
|
||||
["nodeType"]=>
|
||||
int(0)
|
||||
["prefix"]=>
|
||||
string(0) ""
|
||||
["value"]=>
|
||||
string(0) ""
|
||||
["xmlLang"]=>
|
||||
string(0) ""
|
||||
}
|
||||
Failed to read property because no XML data has been read yet
|
||||
bool(true)
|
||||
int(1)
|
||||
|
||||
42
ext/xmlreader/tests/var_dump.phpt
Normal file
42
ext/xmlreader/tests/var_dump.phpt
Normal file
@@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
XMLReader - var_dump
|
||||
--EXTENSIONS--
|
||||
xmlreader
|
||||
--FILE--
|
||||
<?php
|
||||
$reader = XMLReader::fromString("<root>hi</root>");
|
||||
var_dump($reader->read());
|
||||
var_dump($reader);
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
object(XMLReader)#%d (14) {
|
||||
["attributeCount"]=>
|
||||
int(0)
|
||||
["baseURI"]=>
|
||||
string(%d) "%s"
|
||||
["depth"]=>
|
||||
int(0)
|
||||
["hasAttributes"]=>
|
||||
bool(false)
|
||||
["hasValue"]=>
|
||||
bool(false)
|
||||
["isDefault"]=>
|
||||
bool(false)
|
||||
["isEmptyElement"]=>
|
||||
bool(false)
|
||||
["localName"]=>
|
||||
string(4) "root"
|
||||
["name"]=>
|
||||
string(4) "root"
|
||||
["namespaceURI"]=>
|
||||
string(0) ""
|
||||
["nodeType"]=>
|
||||
int(1)
|
||||
["prefix"]=>
|
||||
string(0) ""
|
||||
["value"]=>
|
||||
string(0) ""
|
||||
["xmlLang"]=>
|
||||
string(0) ""
|
||||
}
|
||||
Reference in New Issue
Block a user