Jump to content

Variable question.


spires

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.