Skip to content

Instantly share code, notes, and snippets.

@dhotson
Created September 23, 2010 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhotson/593525 to your computer and use it in GitHub Desktop.
Save dhotson/593525 to your computer and use it in GitHub Desktop.
<?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();
@rbone
Copy link

rbone commented Sep 24, 2010

Needs more xml:
$cat = $xmlclass->load('








name









Hello, my name is \n


');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment