Jump to content

Fatal error: Class 'Test' not found in..... - Creating a class instance


webbiz

Recommended Posts

Hi,

I’m having trouble creating a class instance. The code I’m using works on another server so I’m thinking it must be some settings that are wrong.

The error message I get is: Fatal error: Class 'Test' not found in /mounted-storage/home30a/sub001/sc15979-ERWX/XXXdomainNameXXX/INDEX/test.php on line 6

The class include file seems to get included into the calling file OK. Example code of both the test class and calling page are bellow.

I hope someone can help me out here as it is bound to be some simple setting or something.

 

Thanks,

Lance

 

 

The test code I have:

 

Class:

 

<?php 
class Test{
public function __construct(){
?>
<script type="text/javascript">alert('test class');</script>
<?php
}
}
?>

 

Caller:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php 
include_once('http://www.THEDOMAINNAME/includes/classes-LIT/test.php');
// create class instance
$testx = new Test();
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

Hi,

Thanks for your reply. You are right but I was using that because I’m trying to includes files under a domain name into a file under a sub domain name. On a test page ‘../xxxx/ works but not on the main index page. I may just have to do some rethinking now that I’m on the right track.

 

Thanks heaps.

 

if your problem occurs when the file is in a subdirectory but not on your main index page, then consider using something like:

 

<?php
include_once($_SERVER['DOCUMENT_ROOT'] . '/includes/classes-LIT/test.php');
?>

 

which is pretty much the "internal" equivalent of referencing a file from the web root.

Hi,

Thanks for your reply. You are right but I was using that because I’m trying to includes files under a domain name into a file under a sub domain name. On a test page ‘../xxxx/ works but not on the main index page. I may just have to do some rethinking now that I’m on the right track.

 

Thanks heaps.

 

Start by noting down the directory you are currently in, then adjust includes accordingly..
echo realpath('.');

to see current working directory, then you can make a relative path accordingly.

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.