Created
September 23, 2010 12:11
-
-
Save dhotson/593525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'oo.php' | |
// A subclass of 'class' that lets you define classes in XML ;-) | |
$xmlclass = $class->extend() | |
->fn('load', function($t, $xml) { | |
$class = $t->new(); | |
$doc = new DOMDocument(); | |
$doc->loadXML($xml); | |
foreach ($doc->getElementsByTagName('def') as $e) | |
$class->def($e->getAttribute('name'), eval('return '.trim($e->textContent).';')); | |
return $class; | |
}); | |
$cat = $xmlclass->load(' | |
<class> | |
<def name="init"> | |
function($t, $name) { $t->name = $name; } | |
</def> | |
<def name="speak"> | |
function($t) { echo "Hello, my name is $t->name\n"; } | |
</def> | |
</class>'); | |
$franklin = $cat->new('Franklin'); | |
$franklin->speak(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs more xml:
$cat = $xmlclass->load('
name
Hello, my name is \n
');