[PR #7345] Correct DOMDocument constructor in test #10444

Open
opened 2026-01-22 16:07:33 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/7345

State: closed
Merged: Yes


http://php.net/manual/en/domdocument.construct.php reads:

public DOMDocument::__construct ([ string $version [, string $encoding ]] )

so new \DOMDocument('UTF-8') is incorrect, should be new \DOMDocument('1.0', 'UTF-8'),

but the top user note explains:

The constuctor arguments are useful if you want to build a new document using createElement, appendChild etc.

By contrast, these arguments are overriden as soon as you load a document from source by calling load() or loadXML().

  • If the source contains an XML declaration specifying an encoding, that encoding is used.
  • If the XML declaration does not specify an encoding, or if the source does not contain a declaration at all, UTF-8 is assumed.

This behaviour applies no matter what you declared when you called new DOMDocument().

so here the argument(s) should rather simply be left out.


The additional CS fixes make it also applicable to master as is.

**Original Pull Request:** https://github.com/doctrine/orm/pull/7345 **State:** closed **Merged:** Yes --- http://php.net/manual/en/domdocument.construct.php reads: ``` public DOMDocument::__construct ([ string $version [, string $encoding ]] ) ``` so `new \DOMDocument('UTF-8')` is incorrect, should be `new \DOMDocument('1.0', 'UTF-8')`, but the top user note explains: > The constuctor arguments are useful if you want to build a new document using createElement, appendChild etc. > > By contrast, these arguments are overriden as soon as you load a document from source by calling load() or loadXML(). > > * If the source contains an XML declaration specifying an encoding, that encoding is used. > * If the XML declaration does not specify an encoding, or if the source does not contain a declaration at all, UTF-8 is assumed. > > This behaviour applies no matter what you declared when you called new DOMDocument(). so here the argument(s) should rather simply be left out. --- The additional CS fixes make it also applicable to `master` as is.
admin added the pull-request label 2026-01-22 16:07:33 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#10444