Пример #1
0
class MyDocument extends DOMDocument
{
    public function __get($name)
    {
        return "MyDocument::__get: {$name}";
    }
}
class MyElement extends DOMElement
{
    public function __get($name)
    {
        return "MyElement::__get: {$name}";
    }
}
// Custom doc
$doc = new MyDocument();
var_dump($doc->version);
// native
var_dump($doc->nonExisting);
// user
// Custom Element
$doc->registerNodeClass('DOMElement', 'MyElement');
$node = $doc->appendChild($doc->createElement('Foo', 'Bar'));
var_dump($node->nodeValue);
var_dump($node->nonExisting);
// Attr
$node->setAttribute('x', 'y');
var_dump($node->getAttributeNode('x')->nodeName);
// inherited
var_dump($node->getAttributeNode('x')->name);
// own
Пример #2
0
        echo "This is function doData";
    }
    public function setData()
    {
        echo "setData";
    }
    public function getData()
    {
    }
    public function cutData()
    {
        try {
            echo "cutData";
            throw new Exception("Exception 1");
            self::cancelData();
        } catch (Exception $e) {
            header("HTTP/1.1 400 Bad request");
            echo "<br>";
            echo $e->getMessage();
            echo "<br>";
        }
    }
    public function cancelData()
    {
        if (true) {
            throw new Exception("Exception 2");
        }
    }
}
MyDocument::init();