How can I extend PHP DOMElement?
Posted
by Michael Tsang
on Stack Overflow
See other posts from Stack Overflow
or by Michael Tsang
Published on 2010-04-20T03:35:38Z
Indexed on
2010/04/20
3:43 UTC
Read the original article
Hit count: 296
a.php
#!/usr/bin/php
<?php
class HtmlTable extends DOMElement
{
public function __construct($height, $width)
{
parent::__construct("table");
for ($i = 0; $i < $height; ++$i) {
$row = $this->appendChild(new DOMElement("tr"));
for($j = 0; $j < $width; ++$j) {
$row->appendChild(new DOMElement("td"));
}
}
}
}
$document = new DOMDocument("1.0", "UTF-8");
$document->registerNodeClass("DOMElement", "HtmlTable");
$document->appendChild(new HtmlTable(3, 2));
$document->saveXML();
Running it gets
Fatal error: Uncaught exception 'DOMException' with message 'No Modification Allowed Error' in /home/www/a.php:9
Stack trace:
#0 /home/www/a.php(9): DOMNode->appendChild(Object(DOMElement))
#1 /home/www/a.php(19): HtmlTable->__construct(3, 2)
#2 {main}
thrown in /home/www/a.php on line 9
© Stack Overflow or respective owner