Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,018 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,470 people online right now. Registration is fast and FREE... Join Now!




Use variable to select class

 
Reply to this topicStart new topic

Use variable to select class

BetaWar
11 Dec, 2006 - 03:57 PM
Post #1

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
My Contributions
Okay I am currently working on a program to check if a class exists, if not it returns a different class name, if it does though it returns the class name. This part works, however I am wanting to get it to then use the given class (in the variable) and use a function from the class. This is giving me the error:


Fatal error: Call to a member function on a non-object in /usr/export/www/hosting/threeskulls/pindex.php on line 64


And the code in question is:

CODE
<?
$pageToInclude='main';
$data = array("page_title" => setup::title(),
"motto" => setup::motto(),
"menu" => setup::menu(),
"content" => $pageToInclude->content()
        );
?>


I thought that this should work but it just seems to give me problems, any ideas on how to make it work?
User is online!Profile CardPM
+Quote Post

snoj
RE: Use Variable To Select Class
11 Dec, 2006 - 04:13 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
$pageToInclude is a string, it needs to be an object for you to put that off.

You either need to make use of call_user_func() or call_user_func_array() or do it like this $$pageToInclude which will use the variable $main.
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Use Variable To Select Class
11 Dec, 2006 - 06:45 PM
Post #3

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
My Contributions
Okay thanks for that, I also found out what I was doing wrong, sadly it took a while to fix and I was lost for a bit so I just used the call_user_func() function.

Here is how it should look:

CODE
<?
$pageToInclude= &New main;
$data = array("page_title" => setup::title(),
"motto" => setup::motto(),
"menu" => setup::menu(),
"content" => $pageToInclude->content()
        );
?>

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:09PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month