]> granicus.if.org Git - php/commitdiff
Promote warnings to error in DOM extension
authorGeorge Peter Banyard <girgias@php.net>
Sun, 19 Apr 2020 12:35:25 +0000 (14:35 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 22 Sep 2020 18:12:32 +0000 (19:12 +0100)
Closes GH-5418

25 files changed:
ext/dom/attr.c
ext/dom/cdatasection.c
ext/dom/comment.c
ext/dom/document.c
ext/dom/documentfragment.c
ext/dom/domimplementation.c
ext/dom/element.c
ext/dom/entityreference.c
ext/dom/namednodemap.c
ext/dom/node.c
ext/dom/php_dom.c
ext/dom/php_dom.h
ext/dom/php_dom.stub.php
ext/dom/php_dom_arginfo.h
ext/dom/processinginstruction.c
ext/dom/tests/DOMAttr_ownerElement_error_001.phpt
ext/dom/tests/DOMDocument_adoptNode.phpt
ext/dom/tests/DOMDocument_encoding_basic.phpt
ext/dom/tests/DOMNode_C14NFile_basic.phpt
ext/dom/tests/DOMNode_C14N_basic.phpt
ext/dom/tests/bug36756.phpt
ext/dom/tests/bug77569.phpt
ext/dom/tests/domxpath.phpt
ext/dom/text.c
ext/dom/xpath.c

index 99178bfe3e9ba7544cea8f72497f0f27be3fda55..e348f8fc5abafe930a0c8498ba0a82ccb2b97ebd 100644 (file)
@@ -50,14 +50,14 @@ PHP_METHOD(DOMAttr, __construct)
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        nodep = xmlNewProp(NULL, (xmlChar *) name, (xmlChar *) value);
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        oldnode = dom_object_get_node(intern);
index ce62377917745d45d99cf4f676d2c274d3c09f3e..2d6fd8dc05c6cc5095bf7e0778568119d3314afb 100644 (file)
@@ -46,7 +46,7 @@ PHP_METHOD(DOMCdataSection, __construct)
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               return;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
index db2341b72584fba5ddfe04f8997b7340715afbaf..79588f0c87abb9bf9598a3c92c971a3d325c13c3 100644 (file)
@@ -46,7 +46,7 @@ PHP_METHOD(DOMComment, __construct)
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               return;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
index 6ff1750137187933f46be3c261680fbb06c9a933..b580842667d3aeac5aad2cd8b4c10d14865197dc 100644 (file)
@@ -136,7 +136,7 @@ int dom_document_encoding_read(dom_object *obj, zval *retval)
        return SUCCESS;
 }
 
-int dom_document_encoding_write(dom_object *obj, zval *newval)
+zend_result dom_document_encoding_write(dom_object *obj, zval *newval)
 {
        xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
        zend_string *str;
@@ -161,7 +161,8 @@ int dom_document_encoding_write(dom_object *obj, zval *newval)
                }
                docp->encoding = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
     } else {
-               php_error_docref(NULL, E_WARNING, "Invalid Document Encoding");
+               zend_value_error("Invalid document encoding");
+               return FAILURE;
     }
 
        zend_string_release_ex(str, 0);
index 641c3f5b34d4528faf3f1f1ee3de729f5795d3e9..051416792d349a8e899c6b0eb48ac8d4d8c1ccd8 100644 (file)
@@ -44,7 +44,7 @@ PHP_METHOD(DOMDocumentFragment, __construct)
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               return;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
index 86ec4a23684feac428032c9ef829e9bc53f9e761..b195af5549c66e54e4b31279d4854b50bfb9851e 100644 (file)
@@ -67,8 +67,8 @@ PHP_METHOD(DOMImplementation, createDocumentType)
        }
 
        if (name_len == 0) {
-               php_error_docref(NULL, E_WARNING, "qualifiedName is required");
-               RETURN_FALSE;
+               zend_argument_value_error(1, "cannot be empty");
+               RETURN_THROWS();
        }
 
        if (publicid_len > 0) {
@@ -134,12 +134,12 @@ PHP_METHOD(DOMImplementation, createDocument)
        if (node != NULL) {
                DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
                if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
-                       php_error_docref(NULL, E_WARNING, "Invalid DocumentType object");
-                       RETURN_FALSE;
+                       zend_argument_value_error(3, "is an invalid DocumentType object");
+                       RETURN_THROWS();
                }
                if (doctype->doc != NULL) {
                        php_dom_throw_error(WRONG_DOCUMENT_ERR, 1);
-                       RETURN_FALSE;
+                       RETURN_THROWS();
                }
        } else {
                doctobj = NULL;
@@ -163,7 +163,7 @@ PHP_METHOD(DOMImplementation, createDocument)
                        xmlFree(localname);
                }
                php_dom_throw_error(errorcode, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        /* currently letting libxml2 set the version string */
@@ -195,9 +195,9 @@ PHP_METHOD(DOMImplementation, createDocument)
                        }
                        xmlFreeDoc(docp);
                        xmlFree(localname);
-                       /* Need some type of error here */
-                       php_error_docref(NULL, E_WARNING, "Unexpected Error");
-                       RETURN_FALSE;
+                       /* Need some better type of error here */
+                       php_dom_throw_error(PHP_ERR, 1);
+                       RETURN_THROWS();
                }
 
                nodep->nsDef = nsptr;
index 41bc7296ca87583b38b6677a7baddc908d0558de..317619001beea8b9b237a9f7a86a101bcfbe411a 100644 (file)
@@ -49,7 +49,7 @@ PHP_METHOD(DOMElement, __construct)
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
-               return;
+               RETURN_THROWS();
        }
 
        /* Namespace logic is separate and only when uri passed in to insure no BC breakage */
@@ -71,7 +71,7 @@ PHP_METHOD(DOMElement, __construct)
                                xmlFreeNode(nodep);
                        }
                        php_dom_throw_error(errorcode, 1);
-                       return;
+                       RETURN_THROWS();
                }
        } else {
            /* If you don't pass a namespace uri, then you can't set a prefix */
@@ -80,14 +80,14 @@ PHP_METHOD(DOMElement, __construct)
                        xmlFree(localname);
                        xmlFree(prefix);
                php_dom_throw_error(NAMESPACE_ERR, 1);
-               return;
+               RETURN_THROWS();
            }
                nodep = xmlNewNode(NULL, (xmlChar *) name);
        }
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               return;
+               RETURN_THROWS();
        }
 
        if (value_len > 0) {
@@ -255,14 +255,14 @@ PHP_METHOD(DOMElement, setAttribute)
        }
 
        if (name_len == 0) {
-               php_error_docref(NULL, E_WARNING, "Attribute Name is required");
-               RETURN_FALSE;
+               zend_argument_value_error(1, "cannot be empty");
+               RETURN_THROWS();
        }
 
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
@@ -294,8 +294,8 @@ PHP_METHOD(DOMElement, setAttribute)
                attr = (xmlNodePtr)xmlSetProp(nodep, (xmlChar *) name, (xmlChar *)value);
        }
        if (!attr) {
-               php_error_docref(NULL, E_WARNING, "No such attribute '%s'", name);
-               RETURN_FALSE;
+               zend_argument_value_error(1, "must be a valid XML attribute");
+               RETURN_THROWS();
        }
 
        DOM_RET_OBJ(attr, &ret, intern);
@@ -424,8 +424,8 @@ PHP_METHOD(DOMElement, setAttributeNode)
        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
 
        if (attrp->type != XML_ATTRIBUTE_NODE) {
-               php_error_docref(NULL, E_WARNING, "Attribute node is required");
-               RETURN_FALSE;
+               zend_argument_value_error(1, "must have the node attribute");
+               RETURN_THROWS();
        }
 
        if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
@@ -628,8 +628,8 @@ PHP_METHOD(DOMElement, setAttributeNS)
        }
 
        if (name_len == 0) {
-               php_error_docref(NULL, E_WARNING, "Attribute Name is required");
-               RETURN_FALSE;
+               zend_argument_value_error(2, "cannot be empty");
+               RETURN_THROWS();
        }
 
        DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
@@ -873,10 +873,10 @@ PHP_METHOD(DOMElement, setAttributeNodeNS)
 
        DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);
 
-       if (attrp->type != XML_ATTRIBUTE_NODE) {
-               php_error_docref(NULL, E_WARNING, "Attribute node is required");
-               RETURN_FALSE;
-       }
+       /* ZPP Guarantees that a DOMAttr class is given, as it is converted to a xmlAttr
+        * to pass to libxml (see http://www.xmlsoft.org/html/libxml-tree.html#xmlAttr)
+        * if it is not of type XML_ATTRIBUTE_NODE it indicates a bug somewhere */
+       ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);
 
        if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
                php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
index 4e45119b48f069d077877fcbea72d107182cb378..635cfe7653c435bfc2f76635b6c44ec905c84c02 100644 (file)
@@ -46,14 +46,14 @@ PHP_METHOD(DOMEntityReference, __construct)
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        node = xmlNewReference(NULL, (xmlChar *) name);
 
        if (!node) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
index fd96003e565f899eba5c6c07644204d4d895724e..26e0551f3bc87eb0560adc598397b8c41dc1090b 100644 (file)
@@ -146,44 +146,42 @@ PHP_METHOD(DOMNamedNodeMap, item)
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
                RETURN_THROWS();
        }
-       if (index >= 0) {
-               if (ZEND_LONG_INT_OVFL(index)) {
-                       php_error_docref(NULL, E_WARNING, "Invalid index");
-                       RETURN_NULL();
-               }
+       if (index < 0 || ZEND_LONG_INT_OVFL(index)) {
+               zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
+               RETURN_THROWS();
+       }
 
-               intern = Z_DOMOBJ_P(id);
+       intern = Z_DOMOBJ_P(id);
 
-               objmap = (dom_nnodemap_object *)intern->ptr;
+       objmap = (dom_nnodemap_object *)intern->ptr;
 
-               if (objmap != NULL) {
-                       if ((objmap->nodetype == XML_NOTATION_NODE) ||
-                               objmap->nodetype == XML_ENTITY_NODE) {
-                               if (objmap->ht) {
-                                       if (objmap->nodetype == XML_ENTITY_NODE) {
-                                               itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
-                                       } else {
-                                               itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
-                                       }
+       if (objmap != NULL) {
+               if ((objmap->nodetype == XML_NOTATION_NODE) ||
+                       objmap->nodetype == XML_ENTITY_NODE) {
+                       if (objmap->ht) {
+                               if (objmap->nodetype == XML_ENTITY_NODE) {
+                                       itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
+                               } else {
+                                       itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
                                }
-                       } else {
-                               nodep = dom_object_get_node(objmap->baseobj);
-                               if (nodep) {
-                                       curnode = (xmlNodePtr)nodep->properties;
-                                       count = 0;
-                                       while (count < index && curnode != NULL) {
-                                               count++;
-                                               curnode = (xmlNodePtr)curnode->next;
-                                       }
-                                       itemnode = curnode;
+                       }
+               } else {
+                       nodep = dom_object_get_node(objmap->baseobj);
+                       if (nodep) {
+                               curnode = (xmlNodePtr)nodep->properties;
+                               count = 0;
+                               while (count < index && curnode != NULL) {
+                                       count++;
+                                       curnode = (xmlNodePtr)curnode->next;
                                }
+                               itemnode = curnode;
                        }
                }
+       }
 
-               if (itemnode) {
-                       DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
-                       return;
-               }
+       if (itemnode) {
+               DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
+               return;
        }
 
        RETVAL_NULL();
index 16a6c6cc54e1e5c13d4f011f649dfd58ef661c14..a6f88b5c0f1bb545112b5d89e514394dc25b4e81 100644 (file)
@@ -97,8 +97,7 @@ int dom_node_node_name_read(dom_object *obj, zval *retval)
                case XML_TEXT_NODE:
                        str = "#text";
                        break;
-               default:
-                       php_error_docref(NULL, E_WARNING, "Invalid Node Type");
+               EMPTY_SWITCH_DEFAULT_CASE();
        }
 
        if (str != NULL) {
@@ -875,6 +874,7 @@ PHP_METHOD(DOMNode, insertBefore)
        }
 
        if (child->type == XML_DOCUMENT_FRAG_NODE && child->children == NULL) {
+               /* TODO Drop Warning? */
                php_error_docref(NULL, E_WARNING, "Document Fragment is empty");
                RETURN_FALSE;
        }
@@ -981,8 +981,8 @@ PHP_METHOD(DOMNode, insertBefore)
        }
 
        if (NULL == new_child) {
-               php_error_docref(NULL, E_WARNING, "Couldn't add newnode as the previous sibling of refnode");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Cannot add newnode as the previous sibling of refnode");
+               RETURN_THROWS();
        }
 
        dom_reconcile_ns(parentp->doc, new_child);
@@ -1074,7 +1074,7 @@ PHP_METHOD(DOMNode, replaceChild)
                DOM_RET_OBJ(oldchild, &ret, intern);
                return;
        } else {
-               php_dom_throw_error(NOT_FOUND_ERR, dom_get_strict_error(intern->document));
+               php_dom_throw_error(NOT_FOUND_ERR, stricterror);
                RETURN_FALSE;
        }
 }
@@ -1173,6 +1173,7 @@ PHP_METHOD(DOMNode, appendChild)
        }
 
        if (child->type == XML_DOCUMENT_FRAG_NODE && child->children == NULL) {
+               /* TODO Drop Warning? */
                php_error_docref(NULL, E_WARNING, "Document Fragment is empty");
                RETURN_FALSE;
        }
@@ -1221,6 +1222,7 @@ PHP_METHOD(DOMNode, appendChild)
        if (new_child == NULL) {
                new_child = xmlAddChild(nodep, child);
                if (new_child == NULL) {
+                       // TODO Convert to Error?
                        php_error_docref(NULL, E_WARNING, "Couldn't append node");
                        RETURN_FALSE;
                }
@@ -1570,8 +1572,8 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
        docp = nodep->doc;
 
        if (! docp) {
-               php_error_docref(NULL, E_WARNING, "Node must be associated with a document");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Node must be associated with a document");
+               RETURN_THROWS();
        }
 
        if (xpath_array == NULL) {
@@ -1587,8 +1589,8 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
                                        xmlXPathFreeObject(xpathobjp);
                                }
                                xmlXPathFreeContext(ctxp);
-                               php_error_docref(NULL, E_WARNING, "XPath query did not return a nodeset.");
-                               RETURN_FALSE;
+                               zend_throw_error(NULL, "XPath query did not return a nodeset");
+                               RETURN_THROWS();
                        }
                }
        } else {
@@ -1598,12 +1600,17 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
                char *xquery;
 
                tmp = zend_hash_str_find(ht, "query", sizeof("query")-1);
-               if (tmp && Z_TYPE_P(tmp) == IS_STRING) {
-                       xquery = Z_STRVAL_P(tmp);
-               } else {
-                       php_error_docref(NULL, E_WARNING, "'query' missing from xpath array or is not a string");
-                       RETURN_FALSE;
+               if (!tmp) {
+                       /* if mode == 0 then $xpath arg is 3, if mode == 1 then $xpath is 4 */
+                       zend_argument_value_error(3 + mode, "must have a \"query\" key");
+                       RETURN_THROWS();
+               }
+               if (Z_TYPE_P(tmp) != IS_STRING) {
+                       /* if mode == 0 then $xpath arg is 3, if mode == 1 then $xpath is 4 */
+                       zend_argument_type_error(3 + mode, "\"query\" option must be a string, %s given", zend_zval_type_name(tmp));
+                       RETURN_THROWS();
                }
+               xquery = Z_STRVAL_P(tmp);
 
                ctxp = xmlXPathNewContext(docp);
                ctxp->node = nodep;
@@ -1631,8 +1638,8 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
                                xmlXPathFreeObject(xpathobjp);
                        }
                        xmlXPathFreeContext(ctxp);
-                       php_error_docref(NULL, E_WARNING, "XPath query did not return a nodeset.");
-                       RETURN_FALSE;
+                       zend_throw_error(NULL, "XPath query did not return a nodeset");
+                       RETURN_THROWS();
                }
        }
 
@@ -1738,6 +1745,7 @@ PHP_METHOD(DOMNode, getNodePath)
 
        value = (char *) xmlGetNodePath(nodep);
        if (value == NULL) {
+               /* TODO Research if can return empty string */
                RETURN_NULL();
        } else {
                RETVAL_STRING(value);
index 8eae00fc03bbed66cac691e721b5591693d46aad..78d22f6a5e05cfc8da08a2a5fd53afd32b13cfe0 100644 (file)
@@ -317,7 +317,9 @@ zval *dom_read_property(zend_object *object, zend_string *name, int type, void *
        if (obj->prop_handler != NULL) {
                hnd = zend_hash_find_ptr(obj->prop_handler, name);
        } else if (instanceof_function(obj->std.ce, dom_node_class_entry)) {
-               php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", ZSTR_VAL(obj->std.ce->name));
+               zend_throw_error(NULL, "Couldn't fetch %s. Node no longer exists", ZSTR_VAL(obj->std.ce->name));
+               retval = &EG(uninitialized_zval);
+               return retval;
        }
 
        if (hnd) {
@@ -466,8 +468,8 @@ PHP_FUNCTION(dom_import_simplexml)
        if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
                DOM_RET_OBJ((xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
        } else {
-               php_error_docref(NULL, E_WARNING, "Invalid Nodetype to import");
-               RETURN_NULL();
+               zend_argument_value_error(1, "is not a valid node type");
+               RETURN_THROWS();
        }
 }
 /* }}} */
@@ -1208,7 +1210,8 @@ PHP_DOM_EXPORT zend_bool php_dom_create_object(xmlNodePtr obj, zval *return_valu
                        break;
                }
                default:
-                       php_error_docref(NULL, E_WARNING, "Unsupported node type: %d", obj->type);
+                       /* TODO Convert to a ZEND assertion? */
+                       zend_throw_error(NULL, "Unsupported node type: %d", obj->type);
                        ZVAL_NULL(return_value);
                        return 0;
        }
index 285980b64644b97381f213d2b77dc084e01efb5f..24e1ea646a05d76ce334ea319acb02fda1e564f9 100644 (file)
@@ -151,8 +151,8 @@ entry = zend_register_internal_class_ex(&ce, parent_ce);
        }
 
 #define DOM_NOT_IMPLEMENTED() \
-       php_error_docref(NULL, E_WARNING, "Not yet implemented"); \
-       return;
+       zend_throw_error(NULL, "Not yet implemented"); \
+       RETURN_THROWS();
 
 #define DOM_NODELIST 0
 #define DOM_NAMEDNODEMAP 1
index 5f15f99e174e59822643d457eae026802545cd1e..bce79c9177d61ced3412e2d9dab4c2f295e6b0d7 100644 (file)
@@ -201,7 +201,7 @@ class DOMElement implements DOMParentNode, DOMChildNode
     /** @return bool */
     public function removeAttribute(string $qualifiedName) {}
 
-    /** @return DOMAttr|false */
+    /** @return void */
     public function removeAttributeNS(?string $namespace, string $localName) {}
 
     /** @return DOMAttr|false */
@@ -210,7 +210,7 @@ class DOMElement implements DOMParentNode, DOMChildNode
     /** @return DOMAttr|bool */
     public function setAttribute(string $qualifiedName, string $value) {}
 
-    /** @return bool|null */
+    /** @return void */
     public function setAttributeNS(?string $namespace, string $qualifiedName, string $value) {}
 
     /** @return DOMAttr|null|false */
index d5da40e46393f7fdd279832f1e24a8ca918dee0a..fb8aaf59f23d99ecc15034451e5a7c8b338df3b3 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 8ac9356f9b19b84e98d335bc9d091b022a0f549d */
+ * Stub hash: 128108b08807ce0b125fc7b963bf3c5b77e6987a */
 
 ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
        ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
index 9255213e7162a2fb6806d24ab8ff56fb161557e6..73367442eb1c7877ddc9ac8c386b25d6aeed2ae1 100644 (file)
@@ -46,14 +46,14 @@ PHP_METHOD(DOMProcessingInstruction, __construct)
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
index e57c3da913c1ec6e441e66adce0d7893e611d97f..67a66ae16ea3565cf12180d9f321ca54fe37db81 100644 (file)
@@ -14,10 +14,11 @@ $document->appendChild($root);
 $attr = $root->setAttribute('category', 'books');
 $document->removeChild($root);
 $root = null;
-var_dump($attr->ownerElement);
+try {
+    var_dump($attr->ownerElement);
+} catch (\Error $e) {
+    echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL;
+}
 ?>
---EXPECTF--
-Warning: Couldn't fetch DOMAttr. Node no longer exists in %s on line %d
-
-Warning: Undefined property: DOMAttr::$ownerElement in %s on line %d
-NULL
+--EXPECT--
+Error: Couldn't fetch DOMAttr. Node no longer exists
index 5fc8e79d9dc313089635bcfbb0fca6c8251956b7..0f0a32ae498ff77fdeaf4469439f59a503138927 100644 (file)
@@ -10,7 +10,11 @@ require_once('skipif.inc');
 $dom = new DOMDocument();
 $dom->loadXML("<root />");
 
-$dom->adoptNode($dom->documentElement);
+try {
+    $dom->adoptNode($dom->documentElement);
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 ?>
---EXPECTF--
-Warning: DOMDocument::adoptNode(): Not yet implemented in %s
+--EXPECT--
+Not yet implemented
index 6ac405da698594e11daeca99d7f905689ea3e2c2..925c84d5f185e100c634dc6701681abb9b6bdfca 100644 (file)
@@ -19,10 +19,14 @@ if( !$dom )
     exit;
 }
 
-echo "Empty Encoding Read: {$dom->encoding}\n";
+echo "Empty Encoding Read: '{$dom->encoding}'\n";
 
-$ret = $dom->encoding = 'NYPHP DOMinatrix';
-echo "Adding invalid encoding: $ret\n";
+try {
+    $ret = $dom->encoding = 'NYPHP DOMinatrix';
+    echo "Adding invalid encoding: $ret\n";
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 $ret = $dom->encoding = 'ISO-8859-1';
 echo "Adding ISO-8859-1 encoding: $ret\n";
@@ -38,11 +42,9 @@ echo "UTF-16 Encoding Read: {$dom->encoding}\n";
 
 
 ?>
---EXPECTF--
-Empty Encoding Read: 
-
-Warning: main(): Invalid Document Encoding in %s on line %d
-Adding invalid encoding: NYPHP DOMinatrix
+--EXPECT--
+Empty Encoding Read: ''
+Invalid document encoding
 Adding ISO-8859-1 encoding: ISO-8859-1
 ISO-8859-1 Encoding Read: ISO-8859-1
 Adding UTF-8 encoding: UTF-8
index b006e47deb7ad88447c7c8e1c4c88089fe9871bf..85a8b6f1a51bd8236f35d7dc0c803200d8487f7b 100644 (file)
@@ -27,6 +27,16 @@ $node = $doc->getElementsByTagName('title')->item(0);
 var_dump($node->C14NFile($output));
 $content = file_get_contents($output);
 var_dump($content);
+try {
+    var_dump($node->C14NFile($output, false, false, []));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump($node->C14NFile($output, false, false, ['query' => []]));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 ?>
 --CLEAN--
 <?php
@@ -36,3 +46,5 @@ unlink($output);
 --EXPECT--
 int(34)
 string(34) "<title>The Grapes of Wrath</title>"
+DOMNode::C14NFile(): Argument #4 ($xpath) must have a "query" key
+DOMNode::C14NFile(): Argument #4 ($xpath) "query" option must be a string, array given
index bbfd7bcefb298c0901ad01a0e16f759d4075de12..79a5366e222f5e022cb0cc907478ad6fa047087a 100644 (file)
@@ -24,6 +24,19 @@ $doc = new DOMDocument();
 $doc->loadXML($xml);
 $node = $doc->getElementsByTagName('title')->item(0);
 var_dump($node->C14N());
+
+try {
+    var_dump($node->C14N(false, false, []));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump($node->C14N(false, false, ['query' => []]));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 ?>
 --EXPECT--
 string(34) "<title>The Grapes of Wrath</title>"
+DOMNode::C14N(): Argument #3 ($xpath) must have a "query" key
+DOMNode::C14N(): Argument #3 ($xpath) "query" option must be a string, array given
index ccf9ba5049bb19b8f71e113c9b263c3ece9cc8bc..bf7aa20276bf09de039f348819454e892ad9b047 100644 (file)
@@ -13,7 +13,6 @@ $node = $xpath->query('/root')->item(0);
 echo $node->nodeName . "\n";
 $dom->removeChild($GLOBALS['dom']->firstChild);
 echo "nodeType: " . $node->nodeType . "\n";
-
 /* Node gets destroyed during removeChild */
 $dom->loadXML('<root><child/></root>');
 $xpath = new DOMXpath($dom);
@@ -21,15 +20,15 @@ $node = $xpath->query('//child')->item(0);
 echo $node->nodeName . "\n";
 $GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild);
 
-echo "nodeType: " . $node->nodeType . "\n";
+try {
+    echo "nodeType: " . $node->nodeType . "\n";
+} catch (\Error $e) {
+    echo get_class($e) . ': ' . $e->getMessage() .\PHP_EOL;
+}
 
 ?>
---EXPECTF--
+--EXPECT--
 root
 nodeType: 1
 child
-
-Warning: Couldn't fetch DOMElement. Node no longer exists in %sbug36756.php on line %d
-
-Warning: Undefined property: DOMElement::$nodeType in %s on line %d
-nodeType:
+Error: Couldn't fetch DOMElement. Node no longer exists
index 9eef2af65a78892ec60180585da2d0dc0802a79c..4c63e263e47d6d797a723bc690e617e644e8ce9b 100644 (file)
@@ -8,7 +8,11 @@ if (!extension_loaded('dom')) die('skip dom extension not available');
 <?php
 $imp = new DOMImplementation;
 $dom = $imp->createDocument("", "");
-$dom->encoding = null;
+try {
+    $dom->encoding = null;
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 ?>
---EXPECTF--
-Warning: main(): Invalid Document Encoding in %s on line %d
+--EXPECT--
+Invalid document encoding
index f67b2584aacbacc8a65bf5da4814a65cb4e01238..32aaffee018695d188ac9cd8b742a6c2957318eb 100644 (file)
@@ -50,9 +50,24 @@ $root->appendChild($dom->createElementNS("urn::default", "testnode", 5));
 
 $avg = $xpath->evaluate('number(php:function("MyAverage", //def:testnode))');
 var_dump($avg);
+
+try {
+    $xpath->registerPHPFunctions('non_existent');
+    $avg = $xpath->evaluate('number(php:function("non_existent", //def:testnode))');
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    $xpath->registerPhpFunctions(['non_existant']);
+    $avg = $xpath->evaluate('number(php:function("non_existent", //def:testnode))');
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 ?>
 --EXPECT--
 myval
 float(1)
 bool(true)
 float(4)
+Unable to call handler non_existent()
+Unable to call handler non_existent()
index b1053b2039bfc2e8852b7cc2b9e71c18b49f1da3..7a45be246360ef04e2e96894e1cbbcb3499ea5eb 100644 (file)
@@ -47,7 +47,7 @@ PHP_METHOD(DOMText, __construct)
 
        if (!nodep) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        intern = Z_DOMOBJ_P(ZEND_THIS);
@@ -122,17 +122,25 @@ PHP_METHOD(DOMText, splitText)
        }
        DOM_GET_OBJ(node, id, xmlNodePtr, intern);
 
+       if (offset < 0) {
+               zend_argument_value_error(1, "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        if (node->type != XML_TEXT_NODE && node->type != XML_CDATA_SECTION_NODE) {
+               /* TODO Add warning? */
                RETURN_FALSE;
        }
 
        cur = xmlNodeGetContent(node);
        if (cur == NULL) {
+               /* TODO Add warning? */
                RETURN_FALSE;
        }
        length = xmlUTF8Strlen(cur);
 
-       if (ZEND_LONG_INT_OVFL(offset) || (int)offset > length || offset < 0) {
+       if (ZEND_LONG_INT_OVFL(offset) || (int)offset > length) {
+               /* TODO Add warning? */
                xmlFree(cur);
                RETURN_FALSE;
        }
@@ -149,6 +157,7 @@ PHP_METHOD(DOMText, splitText)
        xmlFree(second);
 
        if (nnode == NULL) {
+               /* TODO Add warning? */
                RETURN_FALSE;
        }
 
index cc3cbf8433655d6183d88cc5e36767ef08b3fabd..1f97601c426d13d5acc0358e9c705d8caaa19d23 100644 (file)
@@ -136,15 +136,9 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
 
        obj = valuePop(ctxt);
        if (obj->stringval == NULL) {
-               php_error_docref(NULL, E_WARNING, "Handler name must be a string");
+               zend_type_error("Handler name must be a string");
                xmlXPathFreeObject(obj);
-               if (fci.param_count > 0) {
-                       for (i = 0; i < nargs - 1; i++) {
-                               zval_ptr_dtor(&fci.params[i]);
-                       }
-                       efree(fci.params);
-               }
-               return;
+               goto cleanup;
        }
        ZVAL_STRING(&fci.function_name, (char *) obj->stringval);
        xmlXPathFreeObject(obj);
@@ -154,11 +148,11 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
        fci.retval = &retval;
 
        if (!zend_make_callable(&fci.function_name, &callable)) {
-               php_error_docref(NULL, E_WARNING, "Unable to call handler %s()", ZSTR_VAL(callable));
+               zend_throw_error(NULL, "Unable to call handler %s()", ZSTR_VAL(callable));
+               goto cleanup;
        } else if (intern->registerPhpFunctions == 2 && zend_hash_exists(intern->registered_phpfunctions, callable) == 0) {
-               php_error_docref(NULL, E_WARNING, "Not allowed to call handler '%s()'.", ZSTR_VAL(callable));
-               /* Push an empty string, so that we at least have an xslt result... */
-               valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
+               zend_throw_error(NULL, "Not allowed to call handler '%s()'.", ZSTR_VAL(callable));
+               goto cleanup;
        } else {
                result = zend_call_function(&fci, NULL);
                if (result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
@@ -176,8 +170,8 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
                        } else if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) {
                                valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(retval) == IS_TRUE));
                        } else if (Z_TYPE(retval) == IS_OBJECT) {
-                               php_error_docref(NULL, E_WARNING, "A PHP Object cannot be converted to a XPath-string");
-                               valuePush(ctxt, xmlXPathNewString((xmlChar *)""));
+                               zend_type_error("A PHP Object cannot be converted to a XPath-string");
+                               return;
                        } else {
                                zend_string *str = zval_get_string(&retval);
                                valuePush(ctxt, xmlXPathNewString((xmlChar *) ZSTR_VAL(str)));
@@ -186,6 +180,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
                        zval_ptr_dtor(&retval);
                }
        }
+cleanup:
        zend_string_release_ex(callable, 0);
        zval_ptr_dtor_str(&fci.function_name);
        if (fci.param_count > 0) {
@@ -228,7 +223,7 @@ PHP_METHOD(DOMXPath, __construct)
        ctx = xmlXPathNewContext(docp);
        if (ctx == NULL) {
                php_dom_throw_error(INVALID_STATE_ERR, 1);
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        intern = Z_XPATHOBJ_P(ZEND_THIS);
@@ -308,8 +303,8 @@ PHP_METHOD(DOMXPath, registerNamespace)
 
        ctxp = (xmlXPathContextPtr) intern->dom.ptr;
        if (ctxp == NULL) {
-               php_error_docref(NULL, E_WARNING, "Invalid XPath Context");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Invalid XPath Context");
+               RETURN_THROWS();
        }
 
        if (xmlXPathRegisterNs(ctxp, prefix, ns_uri) != 0) {
@@ -352,8 +347,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
 
        ctxp = (xmlXPathContextPtr) intern->dom.ptr;
        if (ctxp == NULL) {
-               php_error_docref(NULL, E_WARNING, "Invalid XPath Context");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Invalid XPath Context");
+               RETURN_THROWS();
        }
 
        docp = (xmlDocPtr) ctxp->doc;
@@ -371,8 +366,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        }
 
        if (nodep && docp != nodep->doc) {
-               php_error_docref(NULL, E_WARNING, "Node From Wrong Document");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "Node from wrong document");
+               RETURN_THROWS();
        }
 
        ctxp->node = nodep;
@@ -401,6 +396,7 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        }
 
        if (! xpathobjp) {
+               /* TODO Add Warning? */
                RETURN_FALSE;
        }