Magically Finding a class
Posted: Mon Oct 04, 2010 11:41 am
Hello folks,
Sorry if my questions are a little lame, I am a Perl dev at heart and am doing some projects in Zend/PHP!, this is a much simpler problem than I want to solve, but basically I want to be able to dynamically resolve class names and call as static method on that class.
lets say
So I could of course do Item::tell(); or Person::tell();
However I want to factor out the 'tell' function to the MyBaseClass as its common to both, however how would I automagically call the correct static class name? if that makes sense?
I tried a experiment like '
But that gives a error?
Any ideas?
$
Sorry if my questions are a little lame, I am a Perl dev at heart and am doing some projects in Zend/PHP!, this is a much simpler problem than I want to solve, but basically I want to be able to dynamically resolve class names and call as static method on that class.
lets say
Code: Select all
class Person extends MyBaseClass {
public static $_test = 'Person';
public static function tell() {
echo Person::$_test;
}
}
class Item extends MyBaseClass {
public static $_test = "Item";
public static function tell() {
echo Item::$_test;
}
}
However I want to factor out the 'tell' function to the MyBaseClass as its common to both, however how would I automagically call the correct static class name? if that makes sense?
I tried a experiment like '
Code: Select all
$class = 'Person';
$class::tell();
Any ideas?
$