Created
March 31, 2009 04:34
-
-
Save speedmax/88058 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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"> |
This file contains hidden or 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 | |
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