View Full Version : A variable error with document_root

08-24-2007, 08:31 PM
Can someone tell me what's wrong with this statement

class myClass{

public $galleryBasePath=$_SERVER["DOCUMENT_ROOT"]."/gallery/";

some functions{


I'm using php 5.1. On a development server.

Maybe something with php.ini?....

08-24-2007, 08:39 PM
The document root directory under which the current script is executing, as defined in the server's configuration file.

Maybe your config file isn't right?

08-24-2007, 08:43 PM
well when I echo it in a test script it works just like it should...

08-24-2007, 08:43 PM
You can only assign constant expressions when you assign a value at the same time you declare a variable in a class. From the php manual for PHP5 classes -

The default value must be a constant expression, not (for example) a variable, a class member or a function call.Your code is using a variable on the right-hand side of the expression.

Edit: Also, if you post the actual error message it would help.

08-24-2007, 09:00 PM
Thanks, that is my problem.

How would you guys define that variable so that all of the functions can access it? I want to keep the document_root variable in case the site ever gets moved.

08-24-2007, 09:04 PM
Put code in the class constructor function to assign the value to the variable.

08-24-2007, 09:07 PM
Brilliant!, thanks