1--TEST--
2Delayed freeing entity reference
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$doc = new DOMDocument;
8$entityRef = $doc->appendChild($doc->createElementNS('some:ns', 'container'))
9    ->appendChild($doc->createEntityReference('nbsp'));
10echo $doc->saveXML(), "\n";
11$entityRef->parentNode->remove();
12echo $doc->saveXML(), "\n";
13var_dump($entityRef->parentNode);
14var_dump($entityRef->nodeName);
15var_dump($entityRef->textContent);
16
17$doc = new DOMDocument;
18$doc->loadXML(<<<'XML'
19<?xml version="1.0"?>
20<!DOCTYPE books [
21<!ENTITY test "entity is only for test purposes">
22]>
23<div/>
24XML);
25$entityRef = $doc->documentElement->appendChild($doc->createEntityReference('test'));
26echo $doc->saveXML(), "\n";
27$entityRef->parentNode->remove();
28unset($doc);
29var_dump($entityRef->nodeName);
30var_dump($entityRef->textContent);
31?>
32--EXPECT--
33<?xml version="1.0"?>
34<container xmlns="some:ns">&nbsp;</container>
35
36<?xml version="1.0"?>
37
38NULL
39string(4) "nbsp"
40string(0) ""
41<?xml version="1.0"?>
42<!DOCTYPE books [
43<!ENTITY test "entity is only for test purposes">
44]>
45<div>&test;</div>
46
47string(4) "test"
48string(0) ""
49