Passing off arguments
Posted: Wed Dec 27, 2006 6:34 pm
Hey all,
I'm not really sure if this is possible but I need a method for passing off arguments from one function to another. Basically what I have is a function that loads a class and returns a new instance of it. Well, some of the classes that get loaded need arguments in class initialization and therefor are failing because my function that returns the class doesn't give any parameters. So basically the function looks like this right now:
And as you can see when I initiate the object I don't give any parameters. Well I have no idea how to get around this and the only thing I can think of is some kind of method of passing off arguments from one function to another. Basically pass off all the arguments (Except for $object) that get sent to the new_ob() function into the class initialization function. For example if I wanted to load a class and pass off "test" as the first argument I should be able to go:
And have the "test" parameter passed as the first parameter for the class initialization. Is this possible with PHP? If not does anyone see any clear methods around this? Thanks.
Cheers,
- Josh
I'm not really sure if this is possible but I need a method for passing off arguments from one function to another. Basically what I have is a function that loads a class and returns a new instance of it. Well, some of the classes that get loaded need arguments in class initialization and therefor are failing because my function that returns the class doesn't give any parameters. So basically the function looks like this right now:
Code: Select all
function new_ob($object) // Required function //
{
if (empty($object))
{
throw new Exception("Cannot initiate empty object");
}
$path = $this->system->paths['modules'] . $this->name . "/objects/" . $object . ".object.php";
$this->load($path);
if (!class_exists($object))
{
throw new Exception("Cannot initiate non-existent object");
}
return new $object();
}Code: Select all
new_ob("object1", "test");Cheers,
- Josh