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

msg:3593323 | 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 . '"; 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
|
coopster

msg:3593355 | 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.
|
whoisgregg

msg:3593358 | 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

msg:3593360 | 7:41 pm on Mar 6, 2008 (gmt 0) | I see. Many thanks for both answers. Patrick
|
|
|