diff --git a/dictionaries/PropertyMap.php b/dictionaries/PropertyMap.php index c5755235e91..521a1e7e34f 100644 --- a/dictionaries/PropertyMap.php +++ b/dictionaries/PropertyMap.php @@ -113,6 +113,7 @@ 'formatOutput' => 'bool', 'implementation' => 'DOMImplementation', 'lastElementChild' => 'DOMElement|null', + 'ownerDocument' => 'null', 'preserveWhiteSpace' => 'bool', 'recover' => 'bool', 'resolveExternals' => 'bool', @@ -173,7 +174,7 @@ 'nodeName' => 'string', 'nodeType' => 'int', 'nodeValue' => 'string|null', - 'ownerDocument' => 'DOMDocument|null', + 'ownerDocument' => 'DOMDocument', 'parentNode' => 'DOMNode|null', 'prefix' => 'string', 'previousSibling' => 'DOMNode|null', diff --git a/stubs/extensions/dom.phpstub b/stubs/extensions/dom.phpstub index 2520a479902..b240a8d143d 100644 --- a/stubs/extensions/dom.phpstub +++ b/stubs/extensions/dom.phpstub @@ -154,7 +154,7 @@ class DOMNode */ public ?DOMNamedNodeMap $attributes; /** @readonly */ - public ?DOMDocument $ownerDocument; + public DOMDocument $ownerDocument; /** @readonly */ public ?string $namespaceURI; public string $prefix; @@ -242,7 +242,7 @@ class DOMNameSpaceNode /** @readonly */ public ?string $namespaceURI; /** @readonly */ - public ?DOMDocument $ownerDocument; + public DOMDocument $ownerDocument; /** @readonly */ public ?DOMNode $parentNode; } @@ -281,6 +281,8 @@ class DOMDocument extends DOMNode implements DOMParentNode public DOMImplementation $implementation; /** @readonly */ public ?DOMElement $documentElement; + /** @readonly */ + public null $ownerDocument; /** * @deprecated diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index b0189897090..6b667c53f7c 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -424,6 +424,20 @@ function takesList(array $list): void {} $globBrace = glob('abc', GLOB_BRACE); PHP, ]; + yield "ownerDocument's type is non-nullable DOMDocument and always null on DOMDocument itself" => [ + 'code' => 'ownerDocument; + $b = (new DOMNode())->ownerDocument; + $c = (new DOMElement())->ownerDocument; + $d = (new DOMNameSpaceNode())->ownerDocument; + ', + 'assertions' => [ + '$a===' => 'null', + '$b===' => 'DOMDocument', + '$c===' => 'DOMDocument', + '$d===' => 'DOMDocument', + ], + ]; } public function providerInvalidCodeParse(): iterable diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index bf8e00f4ea5..3d066210444 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -718,7 +718,7 @@ class Foo { $a = new DOMElement("foo"); $owner = $a->ownerDocument;', 'assertions' => [ - '$owner' => 'DOMDocument|null', + '$owner' => 'DOMDocument', ], ], 'propertyMapHydration' => [