Skip to content

Accessing Dom\Node properties can can throw TypeError(s) #21097

@mbeccati

Description

@mbeccati

Description

The following code:

<?php

$implementation = new \Dom\Implementation();
$node = $implementation->createDocumentType('html', 'publicId', 'systemId');

$r = new \ReflectionClass($node);
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
    $node->{$p->getName()};
}

Resulted in this output:

Fatal error: Uncaught TypeError: Cannot assign DOMNodeList to property Dom\Node::$childNodes of type Dom\NodeList

But I expected no output instead.

A follow up after #21077 has been fixed, again coming from the same test in the Symfony test suite.

This time however, I've used Reflection in the example to make sure there are no other properties misbehaving after childNodes has been fixed. I didn't assign the issue to @ndossche as I might give it a shot at fixing myself during the weekend.

PHP Version

PHP 8.4.19-dev (cli) (built: Jan 30 2026 19:25:50) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.19-dev, Copyright (c) Zend Technologies

Operating System

Irrelevant

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions