Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:29:05+00:00 2026-05-13T12:29:05+00:00

Is a global PHP CONSTANT available inside of a Class file? define(‘SITE_PATH’, ‘C:/webserver/htdocs/somefolder/’); Then

  • 0

Is a global PHP CONSTANT available inside of a Class file?

define('SITE_PATH', 'C:/webserver/htdocs/somefolder/');

Then in my class file I try this

public $debug_file = SITE_PATH. 'debug/debug.sql';

This does not seem to work though,

Parse error: parse error, expecting
','' or‘;” in
C:\webserver\htdocs\somefolder\includes\classes\Database.class.php
on line 21

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:29:05+00:00Added an answer on May 13, 2026 at 12:29 pm

    You cannot have an expression in a class declaration.

    I would suggest passing the path in:

    public function __construct($path)
    {
        $this->debug_path = $path;
    }
    

    This gives you more flexibility if you ever want to change the path, you don’t have to change a constant, just what you pass in.

    Or you could create multiple objects that all have different paths. This is useful if it is an autoloader class, as you might want to have it load multiple directories.

    $autoloader = new Autoload(dirname(SYS_PATH));
    $autoloader->register_loader();
    
    class Autoload
    {
        public $include_path = "";
    
        public function __construct($include_path="")
        {
            // Set the Include Path
            // TODO: Sanitize Include Path (Remove Trailing Slash)
            if(!empty($include_path))
            {
                $this->include_path = $include_path;
            }
            else
            {
                $this->include_path = get_include_path();
            }
    
            // Check the directory exists.
            if(!file_exists($this->include_path))
            {
                throw new Exception("Bad Include Path Given");
            }
        }
        // .... more stuff ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to define global array constant code in bootstrap.php $adv_types = array('top' =>
Imagine in the Global.asax.cs file I had an instance class as a private field.
I would like to define a class constant using a concatenation of an existing
I'm having trouble with global variables in php. I have a $screen var set
I'm writing an application in PHP that uses a LOT of global variables that
my global.asax looks like this Imports Castle.Windsor Imports Castle.Windsor.Configuration.Interpreters Public Class MvcApplication Inherits System.Web.HttpApplication
I am using a global named mutex for file access synchronization between an ASP.NET
I use the same constant in all my php files. I do not want
While writing this line :- define('APPLICATION_ROOT', $_SERVER('DOCUMENT_ROOT') ); in constants.php in CodeIgniter framework of
So I have a file for constants. I want to let user define them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.