diff options
Diffstat (limited to 'ext/simplexml')
-rw-r--r-- | ext/simplexml/php_simplexml.h | 2 | ||||
-rw-r--r-- | ext/simplexml/php_simplexml_exports.h | 2 | ||||
-rw-r--r-- | ext/simplexml/simplexml.c | 338 | ||||
-rw-r--r-- | ext/simplexml/simplexml.stub.php | 53 | ||||
-rw-r--r-- | ext/simplexml/simplexml_arginfo.h | 76 | ||||
-rw-r--r-- | ext/simplexml/sxe.c | 22 | ||||
-rw-r--r-- | ext/simplexml/sxe.h | 2 | ||||
-rw-r--r-- | ext/simplexml/sxe.stub.php | 25 | ||||
-rw-r--r-- | ext/simplexml/sxe_arginfo.h | 16 | ||||
-rw-r--r-- | ext/simplexml/tests/SimpleXMLElement_xpath_3.phpt | 20 | ||||
-rw-r--r-- | ext/simplexml/tests/SimpleXMLElement_xpath_4.phpt | 2 | ||||
-rw-r--r-- | ext/simplexml/tests/bug37565.phpt | 4 | ||||
-rw-r--r-- | ext/simplexml/tests/bug38406.phpt | 2 |
13 files changed, 313 insertions, 251 deletions
diff --git a/ext/simplexml/php_simplexml.h b/ext/simplexml/php_simplexml.h index 09752229ac..164525d7b6 100644 --- a/ext/simplexml/php_simplexml.h +++ b/ext/simplexml/php_simplexml.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/ext/simplexml/php_simplexml_exports.h b/ext/simplexml/php_simplexml_exports.h index 20e9785162..748a59317d 100644 --- a/ext/simplexml/php_simplexml_exports.h +++ b/ext/simplexml/php_simplexml_exports.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 2cdff0e648..563856393a 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -30,6 +28,7 @@ #include "ext/standard/php_string.h" #include "php_simplexml.h" #include "php_simplexml_exports.h" +#include "simplexml_arginfo.h" #include "zend_exceptions.h" #include "zend_interfaces.h" #include "sxe.h" @@ -50,13 +49,13 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry() /* {{{ */ static php_sxe_object* php_sxe_object_new(zend_class_entry *ce, zend_function *fptr_count); static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data); static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data); -static zval *sxe_get_value(zval *z, zval *rv); static void php_sxe_iterator_dtor(zend_object_iterator *iter); static int php_sxe_iterator_valid(zend_object_iterator *iter); static zval *php_sxe_iterator_current_data(zend_object_iterator *iter); static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key); static void php_sxe_iterator_move_forward(zend_object_iterator *iter); static void php_sxe_iterator_rewind(zend_object_iterator *iter); +static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type); /* {{{ _node_as_zval() */ @@ -228,7 +227,7 @@ next_iter: /* {{{ sxe_prop_dim_read() */ -static zval *sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, zend_bool attribs, int type, zval *rv) +static zval *sxe_prop_dim_read(zend_object *object, zval *member, zend_bool elements, zend_bool attribs, int type, zval *rv) { php_sxe_object *sxe; char *name; @@ -238,7 +237,7 @@ static zval *sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, z int nodendx = 0; int test = 0; - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); if (!member) { if (sxe->iter.type == SXE_ITER_ATTRLIST) { @@ -369,15 +368,17 @@ long_dim: /* {{{ sxe_property_read() */ -static zval *sxe_property_read(zval *object, zval *member, int type, void **cache_slot, zval *rv) +static zval *sxe_property_read(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv) { - return sxe_prop_dim_read(object, member, 1, 0, type, rv); + zval member; + ZVAL_STR(&member, name); + return sxe_prop_dim_read(object, &member, 1, 0, type, rv); } /* }}} */ /* {{{ sxe_dimension_read() */ -static zval *sxe_dimension_read(zval *object, zval *offset, int type, zval *rv) +static zval *sxe_dimension_read(zend_object *object, zval *offset, int type, zval *rv) { return sxe_prop_dim_read(object, offset, 0, 1, type, rv); } @@ -419,7 +420,7 @@ static void change_node_zval(xmlNodePtr node, zval *value) /* {{{ sxe_property_write() */ -static zval *sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode) +static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value, zend_bool elements, zend_bool attribs, xmlNodePtr *pnewnode) { php_sxe_object *sxe; xmlNodePtr node; @@ -436,7 +437,7 @@ static zval *sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bo zval tmp_zv, zval_copy; zend_string *trim_str; - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); if (!member) { if (sxe->iter.type == SXE_ITER_ATTRLIST) { @@ -525,7 +526,12 @@ long_dim: break; case IS_OBJECT: if (Z_OBJCE_P(value) == sxe_class_entry) { - value = sxe_get_value(value, &zval_copy); + if (sxe_object_cast_ex(Z_OBJ_P(value), &zval_copy, IS_STRING) == FAILURE) { + zend_error(E_ERROR, "Unable to cast node to string"); + /* FIXME: Should not be fatal */ + } + + value = &zval_copy; new_value = 1; break; } @@ -656,42 +662,41 @@ next_iter: /* {{{ sxe_property_write() */ -static zval *sxe_property_write(zval *object, zval *member, zval *value, void **cache_slot) +static zval *sxe_property_write(zend_object *object, zend_string *name, zval *value, void **cache_slot) { - zval *retval = sxe_prop_dim_write(object, member, value, 1, 0, NULL); - + zval member; + ZVAL_STR(&member, name); + zval *retval = sxe_prop_dim_write(object, &member, value, 1, 0, NULL); return retval == &EG(error_zval) ? &EG(uninitialized_zval) : retval; } /* }}} */ /* {{{ sxe_dimension_write() */ -static void sxe_dimension_write(zval *object, zval *offset, zval *value) +static void sxe_dimension_write(zend_object *object, zval *offset, zval *value) { sxe_prop_dim_write(object, offset, value, 0, 1, NULL); } /* }}} */ -static zval *sxe_property_get_adr(zval *object, zval *member, int fetch_type, void **cache_slot) /* {{{ */ +static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int fetch_type, void **cache_slot) /* {{{ */ { php_sxe_object *sxe; xmlNodePtr node; zval ret; char *name; SXE_ITER type; + zval member; - if (!try_convert_to_string(member)) { - return NULL; - } - - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); GET_NODE(sxe, node); - name = Z_STRVAL_P(member); + name = ZSTR_VAL(zname); node = sxe_get_element_by_name(sxe, node, &name, &type); if (node) { return NULL; } - if (sxe_prop_dim_write(object, member, NULL, 1, 0, &node) == &EG(error_zval)) { + ZVAL_STR(&member, zname); + if (sxe_prop_dim_write(object, &member, NULL, 1, 0, &node) == &EG(error_zval)) { return NULL; } type = SXE_ITER_NONE; @@ -711,7 +716,7 @@ static zval *sxe_property_get_adr(zval *object, zval *member, int fetch_type, vo /* {{{ sxe_prop_dim_exists() */ -static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend_bool elements, zend_bool attribs) +static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empty, zend_bool elements, zend_bool attribs) { php_sxe_object *sxe; xmlNodePtr node; @@ -729,7 +734,7 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend member = &tmp_zv; } - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); GET_NODE(sxe, node); @@ -817,15 +822,17 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend /* {{{ sxe_property_exists() */ -static int sxe_property_exists(zval *object, zval *member, int check_empty, void **cache_slot) +static int sxe_property_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot) { - return sxe_prop_dim_exists(object, member, check_empty, 1, 0); + zval member; + ZVAL_STR(&member, name); + return sxe_prop_dim_exists(object, &member, check_empty, 1, 0); } /* }}} */ /* {{{ sxe_dimension_exists() */ -static int sxe_dimension_exists(zval *object, zval *member, int check_empty) +static int sxe_dimension_exists(zend_object *object, zval *member, int check_empty) { return sxe_prop_dim_exists(object, member, check_empty, 0, 1); } @@ -833,7 +840,7 @@ static int sxe_dimension_exists(zval *object, zval *member, int check_empty) /* {{{ sxe_prop_dim_delete() */ -static void sxe_prop_dim_delete(zval *object, zval *member, zend_bool elements, zend_bool attribs) +static void sxe_prop_dim_delete(zend_object *object, zval *member, zend_bool elements, zend_bool attribs) { php_sxe_object *sxe; xmlNodePtr node; @@ -852,7 +859,7 @@ static void sxe_prop_dim_delete(zval *object, zval *member, zend_bool elements, member = &tmp_zv; } - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); GET_NODE(sxe, node); @@ -944,15 +951,17 @@ next_iter: /* {{{ sxe_property_delete() */ -static void sxe_property_delete(zval *object, zval *member, void **cache_slot) +static void sxe_property_delete(zend_object *object, zend_string *name, void **cache_slot) { - sxe_prop_dim_delete(object, member, 1, 0); + zval member; + ZVAL_STR(&member, name); + sxe_prop_dim_delete(object, &member, 1, 0); } /* }}} */ /* {{{ sxe_dimension_unset() */ -static void sxe_dimension_delete(zval *object, zval *offset) +static void sxe_dimension_delete(zend_object *object, zval *offset) { sxe_prop_dim_delete(object, offset, 0, 1); } @@ -1026,7 +1035,7 @@ static void sxe_properties_add(HashTable *rv, char *name, int namelen, zval *val } /* }}} */ -static int sxe_prop_is_empty(zval *object) /* {{{ */ +static int sxe_prop_is_empty(zend_object *object) /* {{{ */ { php_sxe_object *sxe; xmlNodePtr node; @@ -1036,7 +1045,7 @@ static int sxe_prop_is_empty(zval *object) /* {{{ */ int is_empty; int use_iter = 0; - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); GET_NODE(sxe, node); if (!node) { @@ -1119,7 +1128,7 @@ next_iter: } /* }}} */ -static HashTable *sxe_get_prop_hash(zval *object, int is_debug) /* {{{ */ +static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */ { zval value; zval zattr; @@ -1135,7 +1144,7 @@ static HashTable *sxe_get_prop_hash(zval *object, int is_debug) /* {{{ */ use_iter = 0; - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); if (is_debug) { rv = zend_new_array(0); @@ -1249,9 +1258,9 @@ next_iter: } /* }}} */ -static HashTable *sxe_get_gc(zval *object, zval **table, int *n) /* {{{ */ { +static HashTable *sxe_get_gc(zend_object *object, zval **table, int *n) /* {{{ */ { php_sxe_object *sxe; - sxe = Z_SXEOBJ_P(object); + sxe = php_sxe_fetch_object(object); *table = NULL; *n = 0; @@ -1259,13 +1268,13 @@ static HashTable *sxe_get_gc(zval *object, zval **table, int *n) /* {{{ */ { } /* }}} */ -static HashTable *sxe_get_properties(zval *object) /* {{{ */ +static HashTable *sxe_get_properties(zend_object *object) /* {{{ */ { return sxe_get_prop_hash(object, 0); } /* }}} */ -static HashTable * sxe_get_debug_info(zval *object, int *is_temp) /* {{{ */ +static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */ { *is_temp = 1; return sxe_get_prop_hash(object, 1); @@ -1277,6 +1286,8 @@ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */ php_sxe_object *sxe1; php_sxe_object *sxe2; + ZEND_COMPARE_OBJECTS_FALLBACK(object1, object2); + sxe1 = Z_SXEOBJ_P(object1); sxe2 = Z_SXEOBJ_P(object2); @@ -1403,7 +1414,7 @@ SXE_METHOD(registerXPathNamespace) } if (xmlXPathRegisterNs(sxe->xpath, (xmlChar *)prefix, (xmlChar *)ns_uri) != 0) { - RETURN_FALSE + RETURN_FALSE; } RETURN_TRUE; } @@ -1419,88 +1430,76 @@ SXE_METHOD(asXML) xmlOutputBufferPtr outbuf; xmlChar *strval; int strval_len; - char *filename; + char *filename = NULL; size_t filename_len; - if (ZEND_NUM_ARGS() > 1) { - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) { - RETURN_FALSE; - } - - sxe = Z_SXEOBJ_P(ZEND_THIS); - GET_NODE(sxe, node); - node = php_sxe_get_first_node(sxe, node); - - if (node) { - if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) { - int bytes; - bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr); - if (bytes == -1) { - RETURN_FALSE; - } else { - RETURN_TRUE; - } - } else { - outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0); - - if (outbuf == NULL) { - RETURN_FALSE; - } - - xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, NULL); - xmlOutputBufferClose(outbuf); - RETURN_TRUE; - } - } else { - RETURN_FALSE; - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|p", &filename, &filename_len) == FAILURE) { + return; } sxe = Z_SXEOBJ_P(ZEND_THIS); GET_NODE(sxe, node); node = php_sxe_get_first_node(sxe, node); - if (node) { + if (!node) { + RETURN_FALSE; + } + + if (filename) { if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) { - xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding); - if (!strval) { - RETVAL_FALSE; + int bytes; + bytes = xmlSaveFile(filename, (xmlDocPtr) sxe->document->ptr); + if (bytes == -1) { + RETURN_FALSE; } else { - RETVAL_STRINGL((char *)strval, strval_len); + RETURN_TRUE; } - xmlFree(strval); } else { - char *return_content; - size_t return_len; - /* Should we be passing encoding information instead of NULL? */ - outbuf = xmlAllocOutputBuffer(NULL); + outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0); if (outbuf == NULL) { RETURN_FALSE; } - xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding); - xmlOutputBufferFlush(outbuf); + xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, NULL); + xmlOutputBufferClose(outbuf); + RETURN_TRUE; + } + } + + if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) { + xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding); + if (!strval) { + RETVAL_FALSE; + } else { + RETVAL_STRINGL((char *)strval, strval_len); + } + xmlFree(strval); + } else { + char *return_content; + size_t return_len; + /* Should we be passing encoding information instead of NULL? */ + outbuf = xmlAllocOutputBuffer(NULL); + + if (outbuf == NULL) { + RETURN_FALSE; + } + + xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding); + xmlOutputBufferFlush(outbuf); #ifdef LIBXML2_NEW_BUFFER - return_content = (char *)xmlOutputBufferGetContent(outbuf); - return_len = xmlOutputBufferGetSize(outbuf); + return_content = (char *)xmlOutputBufferGetContent(outbuf); + return_len = xmlOutputBufferGetSize(outbuf); #else - return_content = (char *)outbuf->buffer->content; - return_len = outbuf->buffer->use; + return_content = (char *)outbuf->buffer->content; + return_len = outbuf->buffer->use; #endif - if (!return_content) { - RETVAL_FALSE; - } else { - RETVAL_STRINGL(return_content, return_len); - } - xmlOutputBufferClose(outbuf); + if (!return_content) { + RETVAL_FALSE; + } else { + RETVAL_STRINGL(return_content, return_len); } - } else { - RETVAL_FALSE; + xmlOutputBufferClose(outbuf); } } /* }}} */ @@ -1661,6 +1660,10 @@ SXE_METHOD(getName) xmlNodePtr node; int namelen; + if (zend_parse_parameters_none() == FAILURE) { + return; + } + sxe = Z_SXEOBJ_P(ZEND_THIS); GET_NODE(sxe, node); @@ -1875,14 +1878,14 @@ static int cast_object(zval *object, int type, char *contents) /* {{{ sxe_object_cast() */ -static int sxe_object_cast_ex(zval *readobj, zval *writeobj, int type) +static int sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int type) { php_sxe_object *sxe; xmlChar *contents = NULL; xmlNodePtr node; int rv; - sxe = Z_SXEOBJ_P(readobj); + sxe = php_sxe_fetch_object(readobj); if (type == _IS_BOOL) { node = php_sxe_get_first_node(sxe, NULL); @@ -1924,7 +1927,7 @@ static int sxe_object_cast_ex(zval *readobj, zval *writeobj, int type) /* }}} */ /* {{{ Variant of sxe_object_cast_ex that handles overwritten __toString() method */ -static int sxe_object_cast(zval *readobj, zval *writeobj, int type) +static int sxe_object_cast(zend_object *readobj, zval *writeobj, int type) { if (type == IS_STRING && zend_std_cast_object_tostring(readobj, writeobj, IS_STRING) == SUCCESS @@ -1940,7 +1943,11 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type) Returns the string content */ SXE_METHOD(__toString) { - if (sxe_object_cast_ex(ZEND_THIS, return_value, IS_STRING) != SUCCESS) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + if (sxe_object_cast_ex(Z_OBJ_P(ZEND_THIS), return_value, IS_STRING) != SUCCESS) { zval_ptr_dtor(return_value); RETURN_EMPTY_STRING(); } @@ -1974,10 +1981,10 @@ static int php_sxe_count_elements_helper(php_sxe_object *sxe, zend_long *count) } /* }}} */ -static int sxe_count_elements(zval *object, zend_long *count) /* {{{ */ +static int sxe_count_elements(zend_object *object, zend_long *count) /* {{{ */ { php_sxe_object *intern; - intern = Z_SXEOBJ_P(object); + intern = php_sxe_fetch_object(object); if (intern->fptr_count) { zval rv; zend_call_method_with_0_params(object, intern->zo.ce, &intern->fptr_count, "count", &rv); @@ -2009,25 +2016,14 @@ SXE_METHOD(count) } /* }}} */ -static zval *sxe_get_value(zval *z, zval *rv) /* {{{ */ -{ - if (sxe_object_cast_ex(z, rv, IS_STRING) == FAILURE) { - zend_error(E_ERROR, "Unable to cast node to string"); - /* FIXME: Should not be fatal */ - } - - return rv; -} -/* }}} */ - static zend_object_handlers sxe_object_handlers; /* {{{ sxe_object_clone() */ static zend_object * -sxe_object_clone(zval *object) +sxe_object_clone(zend_object *object) { - php_sxe_object *sxe = Z_SXEOBJ_P(object); + php_sxe_object *sxe = php_sxe_fetch_object(object); php_sxe_object *clone; xmlNodePtr nodep = NULL; xmlDocPtr docp = NULL; @@ -2572,73 +2568,6 @@ PHP_FUNCTION(simplexml_import_dom) } /* }}} */ -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexml_load_file, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, class_name) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, ns) - ZEND_ARG_INFO(0, is_prefix) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexml_load_string, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, class_name) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, ns) - ZEND_ARG_INFO(0, is_prefix) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexml_import_dom, 0, 0, 1) - ZEND_ARG_INFO(0, node) - ZEND_ARG_INFO(0, class_name) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_xpath, 0, 0, 1) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_registerxpathnamespace, 0, 0, 2) - ZEND_ARG_INFO(0, prefix) - ZEND_ARG_INFO(0, ns) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_asxml, 0, 0, 0) - ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_getnamespaces, 0, 0, 0) - ZEND_ARG_INFO(0, recursve) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_getdocnamespaces, 0, 0, 0) - ZEND_ARG_INFO(0, recursve) - ZEND_ARG_INFO(0, from_root) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_children, 0, 0, 0) - ZEND_ARG_INFO(0, ns) - ZEND_ARG_INFO(0, is_prefix) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement__construct, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, data_is_url) - ZEND_ARG_INFO(0, ns) - ZEND_ARG_INFO(0, is_prefix) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_simplexmlelement__void, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexmlelement_addchild, 0, 0, 1) - ZEND_ARG_INFO(0, name) - ZEND_ARG_INFO(0, value) - ZEND_ARG_INFO(0, ns) -ZEND_END_ARG_INFO() -/* }}} */ - static const zend_function_entry simplexml_functions[] = { /* {{{ */ PHP_FE(simplexml_load_file, arginfo_simplexml_load_file) PHP_FE(simplexml_load_string, arginfo_simplexml_load_string) @@ -2676,20 +2605,20 @@ ZEND_GET_MODULE(simplexml) /* the method table */ /* each method can have its own parameters and visibility */ static const zend_function_entry sxe_functions[] = { /* {{{ */ - SXE_ME(__construct, arginfo_simplexmlelement__construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* must be called */ - SXE_ME(asXML, arginfo_simplexmlelement_asxml, ZEND_ACC_PUBLIC) - SXE_MALIAS(saveXML, asXML, arginfo_simplexmlelement_asxml, ZEND_ACC_PUBLIC) - SXE_ME(xpath, arginfo_simplexmlelement_xpath, ZEND_ACC_PUBLIC) - SXE_ME(registerXPathNamespace, arginfo_simplexmlelement_registerxpathnamespace, ZEND_ACC_PUBLIC) - SXE_ME(attributes, arginfo_simplexmlelement_children, ZEND_ACC_PUBLIC) - SXE_ME(children, arginfo_simplexmlelement_children, ZEND_ACC_PUBLIC) - SXE_ME(getNamespaces, arginfo_simplexmlelement_getnamespaces, ZEND_ACC_PUBLIC) - SXE_ME(getDocNamespaces, arginfo_simplexmlelement_getdocnamespaces, ZEND_ACC_PUBLIC) - SXE_ME(getName, arginfo_simplexmlelement__void, ZEND_ACC_PUBLIC) - SXE_ME(addChild, arginfo_simplexmlelement_addchild, ZEND_ACC_PUBLIC) - SXE_ME(addAttribute, arginfo_simplexmlelement_addchild, ZEND_ACC_PUBLIC) - SXE_ME(__toString, arginfo_simplexmlelement__void, ZEND_ACC_PUBLIC) - SXE_ME(count, arginfo_simplexmlelement__void, ZEND_ACC_PUBLIC) + SXE_ME(__construct, arginfo_class_SimpleXMLElement___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) /* must be called */ + SXE_ME(asXML, arginfo_class_SimpleXMLElement_asXML, ZEND_ACC_PUBLIC) + SXE_MALIAS(saveXML, asXML, arginfo_class_SimpleXMLElement_saveXML, ZEND_ACC_PUBLIC) + SXE_ME(xpath, arginfo_class_SimpleXMLElement_xpath, ZEND_ACC_PUBLIC) + SXE_ME(registerXPathNamespace, arginfo_class_SimpleXMLElement_registerXPathNamespace, ZEND_ACC_PUBLIC) + SXE_ME(attributes, arginfo_class_SimpleXMLElement_attributes, ZEND_ACC_PUBLIC) + SXE_ME(children, arginfo_class_SimpleXMLElement_children, ZEND_ACC_PUBLIC) + SXE_ME(getNamespaces, arginfo_class_SimpleXMLElement_getNamespaces, ZEND_ACC_PUBLIC) + SXE_ME(getDocNamespaces, arginfo_class_SimpleXMLElement_getDocNamespaces, ZEND_ACC_PUBLIC) + SXE_ME(getName, arginfo_class_SimpleXMLElement_getName, ZEND_ACC_PUBLIC) + SXE_ME(addChild, arginfo_class_SimpleXMLElement_addChild, ZEND_ACC_PUBLIC) + SXE_ME(addAttribute, arginfo_class_SimpleXMLElement_addAttribute, ZEND_ACC_PUBLIC) + SXE_ME(__toString, arginfo_class_SimpleXMLElement___toString, ZEND_ACC_PUBLIC) + SXE_ME(count, arginfo_class_SimpleXMLElement_count, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */ @@ -2716,13 +2645,12 @@ PHP_MINIT_FUNCTION(simplexml) sxe_object_handlers.read_dimension = sxe_dimension_read; sxe_object_handlers.write_dimension = sxe_dimension_write; sxe_object_handlers.get_property_ptr_ptr = sxe_property_get_adr; - sxe_object_handlers.get = sxe_get_value; sxe_object_handlers.has_property = sxe_property_exists; sxe_object_handlers.unset_property = sxe_property_delete; sxe_object_handlers.has_dimension = sxe_dimension_exists; sxe_object_handlers.unset_dimension = sxe_dimension_delete; sxe_object_handlers.get_properties = sxe_get_properties; - sxe_object_handlers.compare_objects = sxe_objects_compare; + sxe_object_handlers.compare = sxe_objects_compare; sxe_object_handlers.cast_object = sxe_object_cast; sxe_object_handlers.count_elements = sxe_count_elements; sxe_object_handlers.get_debug_info = sxe_get_debug_info; diff --git a/ext/simplexml/simplexml.stub.php b/ext/simplexml/simplexml.stub.php new file mode 100644 index 0000000000..dbbbfcba92 --- /dev/null +++ b/ext/simplexml/simplexml.stub.php @@ -0,0 +1,53 @@ +<?php + +/** @return SimpleXMLElement|false */ +function simplexml_load_file(string $filename, ?string $class_name = SimpleXMLElement::class, int $options = 0, string $ns = '', bool $is_prefix = false) {} + +/** @return SimpleXMLElement|false */ +function simplexml_load_string(string $data, ?string $class_name = SimpleXMLElement::class, int $options = 0, string $ns = '', bool $is_prefix = false) {} + +function simplexml_import_dom(DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {} + +class SimpleXMLElement +{ + /** @return array|false */ + public function xpath(string $path) {} + + /** @return bool */ + public function registerXPathNamespace(string $prefix, string $ns) {} + + /** @return string|bool */ + public function asXML(string $filename = UNKNOWN) {} + + /** @return string|bool */ + public function saveXML(string $filename = UNKNOWN) {} + + /** @return array */ + public function getNamespaces(bool $recursive = false) {} + + /** @return array|false */ + public function getDocNamespaces(bool $recursive = false, bool $from_root = true) {} + + /** @return SimpleXMLIterator */ + public function children(?string $ns = null, bool $is_prefix = false) {} + + /** @return SimpleXMLIterator */ + public function attributes(?string $ns = null, bool $is_prefix = false) {} + + public function __construct(string $data, int $options = 0, bool $data_is_url = false, string $ns = '', bool $is_prefix = false) {} + + /** @return SimpleXMLElement */ + public function addChild(string $name, ?string $value = null, ?string $ns = null) {} + + /** @return SimpleXMLElement */ + public function addAttribute(string $name, ?string $value = null, ?string $ns = null) {} + + /** @return string */ + public function getName() {} + + /** @return string */ + public function __toString() {} + + /** @return int */ + public function count() {} +} diff --git a/ext/simplexml/simplexml_arginfo.h b/ext/simplexml/simplexml_arginfo.h new file mode 100644 index 0000000000..ccbbb47d00 --- /dev/null +++ b/ext/simplexml/simplexml_arginfo.h @@ -0,0 +1,76 @@ +/* This is a generated file, edit the .stub.php file instead. */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexml_load_file, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, is_prefix, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_simplexml_load_string, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, is_prefix, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_simplexml_import_dom, 0, 1, SimpleXMLElement, 1) + ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0) + ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 1) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_xpath, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_registerXPathNamespace, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_asXML, 0, 0, 0) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SimpleXMLElement_saveXML arginfo_class_SimpleXMLElement_asXML + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_getNamespaces, 0, 0, 0) + ZEND_ARG_TYPE_INFO(0, recursive, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_getDocNamespaces, 0, 0, 0) + ZEND_ARG_TYPE_INFO(0, recursive, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, from_root, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_children, 0, 0, 0) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, is_prefix, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SimpleXMLElement_attributes arginfo_class_SimpleXMLElement_children + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement___construct, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, data_is_url, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, is_prefix, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_addChild, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, ns, IS_STRING, 1) +ZEND_END_ARG_INFO() + +#define arginfo_class_SimpleXMLElement_addAttribute arginfo_class_SimpleXMLElement_addChild + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLElement_getName, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SimpleXMLElement___toString arginfo_class_SimpleXMLElement_getName + +#define arginfo_class_SimpleXMLElement_count arginfo_class_SimpleXMLElement_getName diff --git a/ext/simplexml/sxe.c b/ext/simplexml/sxe.c index c60e37e264..c8fce2ccde 100644 --- a/ext/simplexml/sxe.c +++ b/ext/simplexml/sxe.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -29,6 +27,7 @@ #include "ext/spl/php_spl.h" #include "ext/spl/spl_iterators.h" #include "sxe.h" +#include "sxe_arginfo.h" PHP_SXE_API zend_class_entry *ce_SimpleXMLIterator = NULL; PHP_SXE_API zend_class_entry *ce_SimpleXMLElement; @@ -166,19 +165,14 @@ PHP_METHOD(ce_SimpleXMLIterator, getChildren) ZVAL_COPY_DEREF(return_value, data); } -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator__void, 0) -ZEND_END_ARG_INFO() -/* }}} */ - static const zend_function_entry funcs_SimpleXMLIterator[] = { - PHP_ME(ce_SimpleXMLIterator, rewind, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, valid, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, current, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, key, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, next, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, hasChildren, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) - PHP_ME(ce_SimpleXMLIterator, getChildren, arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, rewind, arginfo_class_SimpleXMLIterator_rewind, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, valid, arginfo_class_SimpleXMLIterator_valid, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, current, arginfo_class_SimpleXMLIterator_current, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, key, arginfo_class_SimpleXMLIterator_key, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, next, arginfo_class_SimpleXMLIterator_next, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, hasChildren, arginfo_class_SimpleXMLIterator_hasChildren, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, getChildren, arginfo_class_SimpleXMLIterator_getChildren, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */ diff --git a/ext/simplexml/sxe.h b/ext/simplexml/sxe.h index 6806553acc..771ddea4bb 100644 --- a/ext/simplexml/sxe.h +++ b/ext/simplexml/sxe.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | diff --git a/ext/simplexml/sxe.stub.php b/ext/simplexml/sxe.stub.php new file mode 100644 index 0000000000..98ea3327ba --- /dev/null +++ b/ext/simplexml/sxe.stub.php @@ -0,0 +1,25 @@ +<?php + +class SimpleXMLIterator +{ + /** @return void */ + public function rewind() {} + + /** @return bool */ + public function valid() {} + + /** @return ?SimpleXMLElement */ + public function current() {} + + /** @return string|false */ + public function key() {} + + /** @return void */ + public function next() {} + + /** @return bool */ + public function hasChildren() {} + + /** @return ?SimpleXMLIterator */ + public function getChildren() {} +} diff --git a/ext/simplexml/sxe_arginfo.h b/ext/simplexml/sxe_arginfo.h new file mode 100644 index 0000000000..d3b0c6c479 --- /dev/null +++ b/ext/simplexml/sxe_arginfo.h @@ -0,0 +1,16 @@ +/* This is a generated file, edit the .stub.php file instead. */ + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SimpleXMLIterator_rewind, 0, 0, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_SimpleXMLIterator_valid arginfo_class_SimpleXMLIterator_rewind + +#define arginfo_class_SimpleXMLIterator_current arginfo_class_SimpleXMLIterator_rewind + +#define arginfo_class_SimpleXMLIterator_key arginfo_class_SimpleXMLIterator_rewind + +#define arginfo_class_SimpleXMLIterator_next arginfo_class_SimpleXMLIterator_rewind + +#define arginfo_class_SimpleXMLIterator_hasChildren arginfo_class_SimpleXMLIterator_rewind + +#define arginfo_class_SimpleXMLIterator_getChildren arginfo_class_SimpleXMLIterator_rewind diff --git a/ext/simplexml/tests/SimpleXMLElement_xpath_3.phpt b/ext/simplexml/tests/SimpleXMLElement_xpath_3.phpt deleted file mode 100644 index 8682cf818d..0000000000 --- a/ext/simplexml/tests/SimpleXMLElement_xpath_3.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Testing xpath() with invalid XML ---SKIPIF-- -<?php -if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); -?> ---FILE-- -<?php -$xml = simplexml_load_string("XXXXXXX^",$x,0x6000000000000001); -var_dump($xml->xpath("BBBB")); -?> ---EXPECTF-- -Notice: Undefined variable: x in %s on line %d - -Warning: simplexml_load_string() expects parameter 3 to be int, float given in %s on line %d - -Fatal error: Uncaught Error: Call to a member function xpath() on null in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d diff --git a/ext/simplexml/tests/SimpleXMLElement_xpath_4.phpt b/ext/simplexml/tests/SimpleXMLElement_xpath_4.phpt index 28e0517651..c050ca2dd4 100644 --- a/ext/simplexml/tests/SimpleXMLElement_xpath_4.phpt +++ b/ext/simplexml/tests/SimpleXMLElement_xpath_4.phpt @@ -11,7 +11,7 @@ $xml = simplexml_load_string("XXXXXXX^",$x,0x6000000000000001); var_dump($xml); ?> --EXPECTF-- -Notice: Undefined variable: x in %s on line %d +Warning: Undefined variable: x in %s on line %d Warning: simplexml_load_string(): Invalid options in %s on line %d bool(false) diff --git a/ext/simplexml/tests/bug37565.phpt b/ext/simplexml/tests/bug37565.phpt index 41e42cb907..d20fbd5aca 100644 --- a/ext/simplexml/tests/bug37565.phpt +++ b/ext/simplexml/tests/bug37565.phpt @@ -31,9 +31,5 @@ try { ===DONE=== --EXPECT-- Error: simplexml_load_string() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given -Error: Function Reflection::export() is deprecated -Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given Error: simplexml_load_file() expects parameter 2 to be a class name derived from SimpleXMLElement, 'Setting' given -Error: Function Reflection::export() is deprecated -Error: Argument 1 passed to Reflection::export() must implement interface Reflector, null given ===DONE=== diff --git a/ext/simplexml/tests/bug38406.phpt b/ext/simplexml/tests/bug38406.phpt index ea92229496..51a716cbd3 100644 --- a/ext/simplexml/tests/bug38406.phpt +++ b/ext/simplexml/tests/bug38406.phpt @@ -27,7 +27,7 @@ object(SimpleXMLElement)#%d (1) { string(9) "something" } -Notice: Array to string conversion in %s on line %d +Warning: Array to string conversion in %s on line %d Warning: It is not yet possible to assign complex types to properties in %s on line %d Done |