php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79271 DOMDocumentType extends DOMNode, but doesn't provide $childNodes as DOMNodeList
Submitted: 2020-02-13 17:19 UTC Modified: 2020-02-17 08:13 UTC
From: ca at lsp dot net Assigned: cmb (profile)
Status: Closed Package: DOM XML related
PHP Version: 7.3.14 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ca at lsp dot net
New email:
PHP Version: OS:

 

 [2020-02-13 17:19 UTC] ca at lsp dot net
Description:
------------
---
From manual page: https://php.net/class.domdocumenttype
---

According to the `DOMNode` documentation [1], the `$childNodes` property always refers to a `DOMNodeList`.

However, `DOMDocumentType` extends `DOMNode`, but doesn't provide the property nor supports `hasChildNodes()`.

This means that the following test script causes a Notice.

[1] https://www.php.net/class.domnode.php

Test script:
---------------
$dom = new DOMImplementation();
$type = $dom->createDocumentType('html');
echo get_class($type->childNodes);


Expected result:
----------------
DOMNodeList

Actual result:
--------------
Warning: get_class() expects parameter 1 to be object, null given in test.php on line 5

Call Stack:
    0.0075     398976   1. {main}() test.php:0

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-13 19:04 UTC] requinix@php.net
-Type: Documentation Problem +Type: Bug
 [2020-02-13 19:04 UTC] requinix@php.net
I can't find anything in the spec that says a DocumentType has different behavior from Node regarding its children.
https://dom.spec.whatwg.org/

As such I think this is a code bug: ->childNodes should be an (empty) DOMNodeList.
 [2020-02-14 10:09 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79271: DOMDocumentType::$childNodes is NULL
On GitHub:  https://github.com/php/php-src/pull/5180
Patch:      https://github.com/php/php-src/pull/5180.patch
 [2020-02-17 08:11 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=09669411309b5c18c48b550d89b34e78983118cd
Log: Fix #79271: DOMDocumentType::$childNodes is NULL
 [2020-02-17 08:11 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2020-02-17 08:13 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC