]> granicus.if.org Git - php/commitdiff
Clarify types in XmlReader property handling
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 1 Mar 2021 08:54:24 +0000 (09:54 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 1 Mar 2021 08:54:24 +0000 (09:54 +0100)
Make it clearer that the specified type is really the only type
that can be returned.

ext/xmlreader/php_xmlreader.c

index c264993405f8146b3ba450d80f7ee579b7d52358..b12f53dc7715c8096a86b36067e0299bb49519b9 100644 (file)
@@ -85,7 +85,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) {
-                                       php_error_docref(NULL, E_WARNING, "Internal libxml error returned");
+                                       zend_throw_error(NULL, "Failed to read property due to libxml error");
                                        return FAILURE;
                                }
                        }
@@ -100,15 +100,13 @@ static int xmlreader_property_reader(xmlreader_object *obj, xmlreader_prop_handl
                                ZVAL_EMPTY_STRING(rv);
                        }
                        break;
-               /* this IS_FALSE actually means it's a BOOL type */
-               case IS_FALSE:
+               case _IS_BOOL:
                        ZVAL_BOOL(rv, retint);
                        break;
                case IS_LONG:
                        ZVAL_LONG(rv, retint);
                        break;
-               default:
-                       ZVAL_NULL(rv);
+               EMPTY_SWITCH_DEFAULT_CASE()
        }
 
        return SUCCESS;
@@ -1169,10 +1167,10 @@ PHP_MINIT_FUNCTION(xmlreader)
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "attributeCount", xmlTextReaderAttributeCount, NULL, IS_LONG);
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "baseURI", NULL, xmlTextReaderConstBaseUri, IS_STRING);
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "depth", xmlTextReaderDepth, NULL, IS_LONG);
-       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, IS_FALSE);
-       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, IS_FALSE);
-       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, IS_FALSE);
-       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, IS_FALSE);
+       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasAttributes", xmlTextReaderHasAttributes, NULL, _IS_BOOL);
+       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "hasValue", xmlTextReaderHasValue, NULL, _IS_BOOL);
+       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isDefault", xmlTextReaderIsDefault, NULL, _IS_BOOL);
+       xmlreader_register_prop_handler(&xmlreader_prop_handlers, "isEmptyElement", xmlTextReaderIsEmptyElement, NULL, _IS_BOOL);
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "localName", NULL, xmlTextReaderConstLocalName, IS_STRING);
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "name", NULL, xmlTextReaderConstName, IS_STRING);
        xmlreader_register_prop_handler(&xmlreader_prop_handlers, "namespaceURI", NULL, xmlTextReaderConstNamespaceUri, IS_STRING);