[ create a new paste ] login | about

Link: http://codepad.org/CBsD3eVp    [ raw code | fork ]

PHP, pasted on Oct 7:
<?php
error_reporting(-1);

class MyDocument extends DOMDocument {
	public $foo = 'This is my default value. I should be a DOMElement after construction!';	

	public function __construct() {
		parent::__construct('1.0', 'UTF-8');
		$this->registerNodeClass('DOMDocument', get_class($this));
		$this->foo = $this->appendChild($this->createElement('foo'));
	}
}

// Accessing foo directly as a property of $document.
$document = new MyDocument();
printf("%'.-64s ", '$document = new MyDocument(); $document->foo->ownerDocument '); var_dump($document->foo->ownerDocument); echo "\n";

// Accessing foo stored in a variable while $document still exists.
$foo = $document->foo;
printf("%'.-64s ", '$foo = $document->foo; $foo->ownerDocument '); var_dump($foo->ownerDocument); echo "\n";

// Accessing foo stored in a variable when $document is gone.
unset($document);
printf("%'.-64s ", '$document has now been unset; $foo->ownerDocument '); var_dump($foo->ownerDocument); echo "\n";

// Accessing foo by chaining the getter (and as such, not having the document in scope).
$documentGetter = function () {
	return new MyDocument();
};
printf("%'.-64s ", 'Chaining getter result; $getter()->foo->owner '); var_dump($documentGetter()->foo->ownerDocument); echo "\n";


Create a new paste based on this one


Comments: