Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder ghostz00's Avatar
    Join Date
    Aug 2006
    Posts
    128
    Thanks
    11
    Thanked 2 Times in 2 Posts

    A variable error with document_root

    Can someone tell me what's wrong with this statement

    PHP Code:
    <?php
    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?....
    Greg

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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?

  • #3
    Regular Coder ghostz00's Avatar
    Join Date
    Aug 2006
    Posts
    128
    Thanks
    11
    Thanked 2 Times in 2 Posts
    well when I echo it in a test script it works just like it should...
    Greg

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder ghostz00's Avatar
    Join Date
    Aug 2006
    Posts
    128
    Thanks
    11
    Thanked 2 Times in 2 Posts
    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.
    Greg

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    Put code in the class constructor function to assign the value to the variable.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder ghostz00's Avatar
    Join Date
    Aug 2006
    Posts
    128
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Brilliant!, thanks
    Greg


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •