Hi internals

I'm working on implementing new ext-dom features for PHP 8.4.
Among them is support for the $innerHTML property.
It works, but I was wondering how to handle error reporting with this property 
from a developer PoV.

Normally when you parse an XML/HTML document using the DOM extension you either 
receive warnings or get a list of error objects depending on whether internal 
error handling is enabled (using libxml_use_internal_errors). Error reporting 
can be disabled by passing in LIBXML_NOERROR to the parser. Note that these 
errors can either be hard errors (e.g. parsing XML without recovery enabled), 
or soft errors (e.g. parsing HTML which has recovery rules).
Because $innerHTML is a property, you can't pass the LIBXML_NOERROR option. 
Therefore, it's not possible to suppress potential errors, except when using 
the @ operator but that doesn't stop the error reporting when internal error 
handling is enabled. The current solution I've been thinking about is 
inheriting the LIBXML_NOERROR option if it was used to parse the document 
initially. However, that won't work when a document was created without using a 
parser, e.g. using `XMLDocument::createEmpty()` or 
`$dom->implementation->createDocument(...)`.

It's worth noting that browsers when parsing XML in innerHTML always emit 
errors on malformed XML, with no option to disable it.

Looking forward to hear opinions on this.

Kind regards
Niels

Reply via email to