spires Posted December 17, 2010 Share Posted December 17, 2010 Hi, I have a quick question: is it possible to replace a Class name with a variable? I keep getting an error when I try: Area_town::count_all(); becomes: $className = 'Area_town'; $className::count_all(); I want to make the page dynamic, but to do so, I have to have the Class name as a dynamic name. Error: Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/p/o/powtest/web/public_html/admin/lib/pagination/paging_town_data.php on line 15 Thanks Link to comment https://forums.phpfreaks.com/topic/221980-variable-question/ Share on other sites More sharing options...
trq Posted December 17, 2010 Share Posted December 17, 2010 I'm not in a position to test at the moment but I'm not sure that is possible with un-instantiated classes and static methods. It is possible within objects however. Link to comment https://forums.phpfreaks.com/topic/221980-variable-question/#findComment-1148638 Share on other sites More sharing options...
shlumph Posted December 17, 2010 Share Posted December 17, 2010 This is what you're looking for: http://us.php.net/manual/en/function.call-user-func.php Note that you can also use variable variables: $objectName = 'myclass2Object'; //case sensitive. $anotherObject = 'anotherObject';//case sensitive $functionName = 'adding'; $output = $$objectName->{$anotherObject}->{$functionName}(); echo $output; //will output 9 as well Link to comment https://forums.phpfreaks.com/topic/221980-variable-question/#findComment-1148639 Share on other sites More sharing options...
spires Posted December 17, 2010 Author Share Posted December 17, 2010 Thanks I shall check it out. Link to comment https://forums.phpfreaks.com/topic/221980-variable-question/#findComment-1148641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.