Welcome to WebmasterWorld Guest from 54.144.15.10

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can't instantiate a class with "defined"

Parse error

     
7:06 pm on Mar 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 30, 2003
posts: 932
votes: 0


Code fragment:

// Get the class template
include ('inc/page.class.php');

// Page name
define('PLUME', $cleanfiletitle);
PLUME = new Page; // Parse error on this line

// For .txt filename
$filename = "' . $textfilename . '";

// If it exists...
if (file_exists($filename)) {
$file_contents = file_get_contents($filename);
$output = $file_contents;
} else {
$output = "No content. The associated text file could not be found.";
}

// Variables required by class template
PLUME->Textfilename = "' . $textfilename . '";
PLUME->SetContent($output);
PLUME->Template();

My class is Page. Everything works fine if I use a php variable $cleanfiletitle instead of PLUME. I would appreciate knowing why I get a parse error for the line indicated.

Patrick

7:32 pm on Mar 6, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


PLUME
in this case is a constant [php.net] and a constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script.
7:33 pm on Mar 6, 2008 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


There are two reasons you get an error. First, constants cannot, by definition, be changed after they are initially set. Second, they can only be a scalar value (in other words, numbers, strings, and booleans are okay, but an object reference is not okay.)

Complete details about defining constants here [us3.php.net].

Added: coop beat me to it. :)

7:41 pm on Mar 6, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 30, 2003
posts: 932
votes: 0


I see. Many thanks for both answers.

Patrick