php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80780 var_export return an empty an incomplete representation
Submitted: 2021-02-21 15:55 UTC Modified: 2021-02-22 14:54 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: glash dot gnome at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: Irrelevant OS: GNU Lunix
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-02-21 15:55 UTC] glash dot gnome at gmail dot com
Description:
------------
If I var_export() a DOMDocument, I get an incomplete representation of the DOM data.

"That's funny, it did it a moment ago."
If I var_dump() a DOMDocument, I get a complete representation of the DOM data.

"So then I tried SimpleXML"
If I use SimpleXML, var_export() and var_dump() returns me a full representation of data. 

"Show me."
In an extension, to enable var_dump() we need to implement :
zend_object_handlers.get_debug_info

What should be implemented to enable var_export() ?

Test script:
---------------
$doc = new DOMDocument();
$doc->loadXML("<root><item>Text</item></root>");
var_export($doc);


Expected result:
----------------
DOMDocument::__set_state(array(
  'doctype' => NULL,
  'implementation' => '(object value omitted)',
  'documentElement' => '(object value omitted)',
  'actualEncoding' => NULL,
  'encoding' => NULL,
  'xmlEncoding' => NULL,
  'standalone' => true,
  'xmlStandalone' => true,
  'version' => '1.0',
  'xmlVersion' => '1.0',
  'strictErrorChecking' => true,
  'documentURI' => '[...]',
  'config' => NULL,
  'formatOutput' => false,
  'validateOnParse' => false,
  'resolveExternals' => false,
  'preserveWhiteSpace' => true,
  'recover' => false,
  'substituteEntities' => false,
  'nodeName' => '#document',
  'nodeValue' => NULL,
  'nodeType' => 9,
  'parentNode' => NULL,
  'childNodes' => '(object value omitted)',
  'firstChild' => '(object value omitted)',
  'lastChild' => '(object value omitted)',
  'previousSibling' => NULL,
  'nextSibling' => NULL,
  'attributes' => NULL,
  'ownerDocument' => NULL,
  'namespaceURI' => NULL,
  'prefix' => '',
  'localName' => NULL,
  'baseURI' => '[...]',
  'textContent' => 'Text',
))

Actual result:
--------------
DOMDocument::__set_state(array(
))


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-22 14:54 UTC] cmb@php.net
> In an extension, to enable var_dump() we need to implement :
> zend_object_handlers.get_debug_info

Better implement zend_object_handlers.get_properties_for()[1].
That can be used for var_export() as well, but still evaluating
the results would not work.  I'm not convinced that supporting
var_export() without supporting __set_state() is a good idea.

[1] <https://github.com/php/php-src/pull/5428#issuecomment-620599894>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 03:03:33 2021 UTC