php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76611 Printing DOMNode shows fake "(object value omitted)" strings
Submitted: 2018-07-11 17:45 UTC Modified: 2018-07-21 13:21 UTC
Votes:15
Avg. Score:4.5 ± 0.8
Reproduced:12 of 14 (85.7%)
Same Version:3 (25.0%)
Same OS:2 (16.7%)
From: chealer at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.2.7 OS:
Private report: No CVE-ID: None
 [2018-07-11 17:45 UTC] chealer at gmail dot com
Description:
------------
The DOM extension's DOMNode class seems to hide object properties when DOMNode objects are displayed.

For example, the following shows that print_r() presents the lastChild property as a string "(object value omitted)", but also that this property is in fact a DOMElement object when directly printed.

This affects Xdebug and makes it painful to debug the DOM extension.

https://3v4l.org/NFpRS shows that this persists in 7.3.0 alpha 1.

Test script:
---------------
<?php

$dom = new DOMDocument();
$dom->loadHTML('<h1>Configuration</h1>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
print_r($dom);
print_r($dom->lastChild);

Actual result:
--------------
DOMDocument Object
(
    [doctype] => 
    [implementation] => (object value omitted)
    [documentElement] => (object value omitted)
    [actualEncoding] => 
    [encoding] => 
    [xmlEncoding] => 
    [standalone] => 1
    [xmlStandalone] => 1
    [version] => 
    [xmlVersion] => 
    [strictErrorChecking] => 1
    [documentURI] => 
    [config] => 
    [formatOutput] => 
    [validateOnParse] => 
    [resolveExternals] => 
    [preserveWhiteSpace] => 1
    [recover] => 
    [substituteEntities] => 
    [nodeName] => #document
    [nodeValue] => 
    [nodeType] => 13
    [parentNode] => 
    [childNodes] => (object value omitted)
    [firstChild] => (object value omitted)
    [lastChild] => (object value omitted)
    [previousSibling] => 
    [attributes] => 
    [ownerDocument] => 
    [namespaceURI] => 
    [prefix] => 
    [localName] => 
    [baseURI] => 
    [textContent] => Configuration
)
DOMElement Object
(
    [tagName] => h1
    [schemaTypeInfo] => 
    [nodeName] => h1
    [nodeValue] => Configuration
    [nodeType] => 1
    [parentNode] => (object value omitted)
    [childNodes] => (object value omitted)
    [firstChild] => (object value omitted)
    [lastChild] => (object value omitted)
    [previousSibling] => 
    [attributes] => (object value omitted)
    [ownerDocument] => (object value omitted)
    [namespaceURI] => 
    [prefix] => 
    [localName] => h1
    [baseURI] => 
    [textContent] => Configuration
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-21 13:21 UTC] cmb@php.net
Changing this behavior would be as simple as applying this
patch[1], but I'm not sure that would be an improvement since the
output would be extremly verbose[2].

[1] <https://gist.github.com/cmb69/76137ddce3a084c2893faa73be4c038f#file-verbose-diff>
[2] <https://gist.github.com/cmb69/76137ddce3a084c2893faa73be4c038f#file-out-txt>
 [2018-09-14 08:55 UTC] naitsirch at e dot mail dot de
Yes, this is verbose, but otherwise it is hard to debug code that uses those objects. People who debug with print_r/var_dump can select concrete properties/attributes of the objects to get less output.

Please merge the patch.
 [2019-09-22 22:49 UTC] beberlei@php.net
The patch itself cannot be merged so easily, because it would instantly lead to out of memory for larger XML documents when they suddenly get fully printed to screen. The recursiveness of DOM nodes makes this very painful.

I propose we add a depth limit in a way if thats possible. For now the guard "(object value omitted)" is a good workaround though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 10:01:28 2024 UTC