php-src/ext/dom/tests/DOMDocument_json_encode.phpt
Niels Dossche 6e468bbd3b Fix json_encode result on DOMDocument
According to https://www.php.net/manual/en/class.domdocument:
  When using json_encode() on a DOMDocument object the result will be
  that of encoding an empty object.

But this was broken in 8.1. The output was `{"config": null}`.
That's because the config property is defined with a default value of
NULL, hence it was included. The other properties are not included
because they don't have a default property, and nothing is ever written
to their backing field. Hence, the JSON encoder excludes them.
Similarly, `(array) $doc` would yield the same `config` key in the
array.

Closes GH-11840.
2023-08-01 17:28:51 +02:00

11 lines
136 B
PHP

--TEST--
JSON encoding a DOMDocument
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument;
echo json_encode($doc);
?>
--EXPECT--
{}