Hi there.
I have function that checks to see if the name of a file exists, and if it does, it includes the file and checks to see if there is a function in the file that exists (by the same name). If there is a function, it runs it.
It seems to work ok here (looks for a file named 'test':
$pageName = "test";
if (is_file($pageName . '.inc')){
include($pageName . '.inc');
$is_it_a_function = method_exists($pageName, 'go');
if ($is_it_a_function = true){
echo(call_user_func(array(&$pageName,'go')));
}
}
here is the file named 'test.inc' - it runs the function 'go' in there. Here is the file test.inc:
class test {
function go(){
return("hello world");
}
}
This works!
The problem is that it does not work when I do it this way:
$content = new ContentPage("test","go");
echo ($content->keyIsFunction());
Class ContentPage
{
var $pageKey;
var $pageName;
function ContentPage($pageKey,$pageName)
{
$this->pageKey = $pageKey;
$this->pageName = $pageName;
}
function keyIsFunction(){
if (file_exists($this->pageName . '.inc')){
include($this->pageName . '.inc');
$is_it_a_function = method_exists($this->pageName, $this->pageKey);
if ($is_it_a_function = true)
{$this->innards = call_user_func(array($this->pageName,$this->pageKey));
return $this->innards;
}
}
}
}
If someone could explain why this does not work I would be very grateful... my eyes are starting to hurt.
Thanks,
Matt Reider