Log in

View Full Version : Can you use a class method to include files?



jlizarraga
06-26-2009, 07:34 PM
Hi all,

I want to be able to include files through a class. Here's a stripped down version of the class I've got going to give you an idea of what I'm trying to achieve:


class mm3 {

// getCSS() - Returns standard CSS files depending on page/version.
public function getCSS($page, $version){
switch($page){
case "inventory":
include mmPHPPath.'includes/css-inventory.php';
default:
return false;
}
}

}

But this isn't working. Nothing happens.

mmPHPPath is a constant. If I changed "include" to "echo", the correct PHP path to the file is shown. If I change mmPHPPath to mmInvURL (another constant), then I get a path that if pasted into the browser also brings up the correct file. So I know it's pointing to the right place, but I'm not getting a result.

If I use "require" the script halts, but if I use "include" with a try...catch block the catch statements don't execute.

Blarg! :confused: Thanks for any help.

thetestingsite
06-26-2009, 07:52 PM
Try using:



include(mmPHPPath.'includes/css-inventory.php');


instead.

Hope this helps.

jlizarraga
06-26-2009, 08:00 PM
Still nothing. :(

This also results in nothing:


try{
include(mmPHPPath.'includes/css-inventory.php');
} catch(Exception $e){
echo 'Message: ' .$e->getMessage();
}

Edit: RATS! It turned out to be a stupid typo in my constants. But shouldn't include() throw an exception if it doesn't find the file? How are you supposed to debug include()?

Thanks!