Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created March 31, 2009 04:34
Show Gist options
  • Save speedmax/88058 to your computer and use it in GitHub Desktop.
Save speedmax/88058 to your computer and use it in GitHub Desktop.
<?php
class P extends Object {
static $something;
static function foo() {
return __METHOD__;
}
function bar() {}
}
$c = _class('P');
var_dump($c->ancestors);
# [Object]
var_dump($c->methods);
# ['foo', 'bar']
echo $c->foo() // invoke the static method of foo
# "P::foo"
echo $c->foo
# <Method "P::foo">
$c->something = "else" // set the static attr
echo $c->something;
# "else"
/*
may be even abstract this into our Object super class
*/
$person = new P('sean');
var_dump($person->class->ancestors)
# ["Object"]
// Invoke class method
var_dump($person->class->foo())
# "P::foo"
var_dump($person->class->foo)
# <Method "P::foo">
<?php
class ClassObject extends Object {
function __get($attr) {
switch($attr) {
case 'methods':
return get_class_methods($this->class);
case 'ancestors':
return class_parents($this->class);
}
}
function __call() {}
function __set() {}
function __toString() {}
}
class Method extends Object {
function params() {}
function call() {}
}
function _class($class) {
return new ClassObject ($class);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment