Jump to content

Loading a class from a file - Dynamic class loading


keeB

Recommended Posts

Hello,

 

I want to load a class from a file, and I have tried to do so with little success.

 

Here's a sample of my code:

 

 
include("CMWebServiceImpl.class.php");
$fs = new filesystem();

$data = $fs->readFile("/home/keeb/test.res", "r");

$x = new $data("http://192.168.2.37/services/Router?wsdl");

 

This returns

 

Fatal error: Class 'CMWebServiceImpl ' not found in /home/keeb/projects/php/cmsService/classes/classFromFile.php on line 10

 

However, this is not the case, since I can call with success:

$y = new CMWebServiceImpl("http://192.168.2.37/services/Router?wsdl");

 

Anyone do anything like this before?

 

Thanks,

- Keeb

 

The class name isn't data, the class name is CMWebServiceImpl, from what he showed.  CMWebServiceImpl is stored in $data.  However, from the error that you are showing us, it looks like $data is stored with an extra space at the end.  It is actually: "CMWebServiceImpl " instead of "CMWebServiceImpl".  Check that variable and I'll get back to you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.