Calling class names encapsulated as strings
Posted: Tue Oct 03, 2006 11:23 pm
JayBird | Please use
I can use:
As long as there aren't any calls to the class from within the method such as $this->SomeMethod() this works fine, otherwise I get an error message:
If anyone has a solution to this issue, please let me know.
JayBird | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a content management system that I've been working on for the last few weeks and have run into an issue that I can't seem to figure out. What I would like is to be able to use classes as "modules" that could be activated or deactivated. Those classes would be listed in database form and then called in series. The problem that I've run into is that I can't seem to find anything other than call_user_func as a way of instantiating the objects. Here is an exmple of what I would like to accomplish:Code: Select all
<?php
class TestClass
{
private $property;
function __constructor()
{
$this->property = "Some value";
}
function SomeMethod($inputVar)
{
return $inputVar++;
}
}
$className = "TestClass";
//code that wont work...
$obj = new $className();
?>Code: Select all
$call = array("TestClass","SomeMethod");
echo call_user_func($call,3);Code: Select all
Using $this when not in object contextJayBird | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]