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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.