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:2
Avg. Score:2.0 ± 1.0
Reproduced:2 of 2 (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
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: glash dot gnome at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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>
 [2022-04-22 13:24 UTC] ilutov@php.net
> I'm not convinced that supporting var_export() without supporting __set_state() is a good idea.

Me neither. I would do the opposite, make `var_export` fail if `__set_state` isn't implemented.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 04:01:26 2024 UTC