Web Hosting Talk







View Full Version : Cannot instantiate non-existent class


jowd
03-08-2005, 10:11 AM
OK, I must simply be missing something because it's 6am and I've been sitting in front of the computer for 14 hours...

Here's the error I'm getting:Fatal error: Cannot instantiate non-existent class: page in /home/jopie916/public_html/xzamnet2/index.php on line 10

Contents of index.php:require_once('settings.php');

$contentSrc = $_REQUEST["p"];
if (empty($contentSrc)) {
$contentSrc = ENV_CONTENT_DEFAULT;
}

$oPage = new Page($contentSrc); // <-- line 10
$oPage->Render();
Contents of settings.php:
define("ENV_SERVER_ADDRESS", "http://www.jopie916.com/xzamnet2");
define("ENV_SITE_PATH", "/");
define("ENV_SITE_ROOT", ENV_SERVER_ADDRESS.ENV_SITE_PATH);
define("ENV_CONTENT_DEFAULT", "/");

define("ENV_TEMPLATE_PATH", ENV_SITE_ROOT."Templates/");
define("ENV_TEMPLATE_FILE", ENV_TEMPLATE_PATH."standard_index.php");

define("ENV_CLASSES_PATH", ENV_SITE_ROOT."Classes/");

require_once(ENV_CLASSES_PATH."PageClass.php");Contents of PageClass.php:class Page {

var $deleteme;

function Page($path = "") {
if (empty($path)) {
$path = $_SERVER["PHP_SELF"];
}
$this->pPath = $path;
// $this->ParsePath($this->pPath);
}

function Render() {
// include template page
include(ENV_TEMPLATE_FILE);
}

}Contents of standard_index.php:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
Hi.
</body>
</html>here's the address where it's hosted: http://www.jopie916.com/xzamnet2/

I have verified that all of the files are in the correct directories and that the filenames are correct, and in correct case.

Ideas anyone?

Kamejoko
03-08-2005, 10:18 AM
There might be errors in PageClass.php

$this->pPath = $path;

But I don't see pPath is declared as an attribute of Page class.
Try error_reporting (E_ALL);

jowd
03-08-2005, 10:46 AM
Set to error_reporting (E_ALL) as suggested, I do get an additional error, but it seems unrelated:

Notice: Undefined index: p in /home/jopie916/public_html/xzamnet2/index.php on line 6

If I give p a value (e.g. index.php?p=page) then the new error goes away, but the original error still exists.

jowd
03-08-2005, 10:48 AM
oh, I forgot...

I did also add the variable $pPath to the class. This did not fix the problem either.

Kamejoko
03-08-2005, 11:05 AM
OK now I see that the problem is,

define("ENV_SERVER_ADDRESS", "http://www.jopie916.com/xzamnet2");
define("ENV_SITE_PATH", "/");
define("ENV_SITE_ROOT", ENV_SERVER_ADDRESS.ENV_SITE_PATH);
define("ENV_CONTENT_DEFAULT", "/");

define("ENV_TEMPLATE_PATH", ENV_SITE_ROOT."Templates/");
define("ENV_TEMPLATE_FILE", ENV_TEMPLATE_PATH."standard_index.php");

define("ENV_CLASSES_PATH", ENV_SITE_ROOT."Classes/");

require_once(ENV_CLASSES_PATH."PageClass.php");


If you trace it back, you will see ENV_CLASSES_PATH is
"http://www.jopie916.com/xzamnet2/Classes/"
Then

require_once(ENV_CLASSES_PATH."PageClass.php");

will include the OUTPUT of this URL
http://www.jopie916.com/xzamnet2/Classes/PageClass.php
Just change

define("ENV_SITE_ROOT", ENV_SERVER_ADDRESS.ENV_SITE_PATH);

to

define("ENV_SITE_ROOT", "/home/jopie916/public_html/xzamnet2".ENV_SITE_PATH);

and it will work

jowd
03-08-2005, 05:39 PM
Thanks Kamejoko... That worked. You're a star!

was it outputting the file instead of parsing it because of the "http://www..." in the address?

hiryuu
03-08-2005, 06:33 PM
The 'file' URL was parsed/executed server-side, then passed to your script (the client, in this case). Of course, the library doesn't output anything, so you were just require()ing an empty include.

Also consider setting include_path to meet your needs, rather than building the paths within the code.