homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Can't instantiate a class with "defined"
Parse error
Patrick Taylor

 7:06 pm on Mar 6, 2008 (gmt 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 . '";

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.




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

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)

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. :)

Patrick Taylor

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

I see. Many thanks for both answers.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved