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

  • SEARCH
  • Home
  • 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 7187037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:45:30+00:00 2026-05-28T18:45:30+00:00

Im on php 5.2.x I have a loader class that looks like so: class

  • 0

Im on php 5.2.x

I have a loader class that looks like so:

class Loader {

    static $account_nameClasses = array(
        'DB' => '/home/account_name/public_html/includes/php/DB.php',
        'Skin' => '/home/account_name/public_html/includes/php/Skin.php',
        'API' => '/home/account_name/public_html/api/apiClass.php',
        'Search'  => '/home/account_name/public_html/includes/php/Search.php',
        'User'  => '/home/account_name/public_html/includes/php/User.php'
    );

    static function loader($className) {
        $filename = self::$account_nameClasses[$className];

        if(file_exists($filename)){
            require_once $filename;
        }else{
            return false;
        }
    }
}

spl_autoload_register(array(account_name_Loader, 'loader'));

As you can see, I repeat /home/account_name/public_html/includes/php/ over and over.

I want to replace that with a constant (or anything else) so that I can easily change it if I move the location of the app.

I tried this (Any may forms of this), but it just doesn’t work

const PHP_CLASSES_ROOT = '/home/account_name/www/';

static $account_nameClasses = array(
    'DB' => self::PHP_CLASSES_ROOT.'DB.php',
    'Skin' => self::PHP_CLASSES_ROOT.'Skin.php',
    'Search'  => self::PHP_CLASSES_ROOT.'Search.php',
    'User'  => self::PHP_CLASSES_ROOT.'User.php'
);

Any ideas?

  • 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-28T18:45:31+00:00Added an answer on May 28, 2026 at 6:45 pm

    You can modify the loader function:

    class Loader {
        const PHP_CLASSES_ROOT = '/home/account_name/public_html/includes/php/';
    
        static $account_nameClasses = array(
            'DB' => 'DB.php',
            'Skin' => 'Skin.php',
            'API' => 'apiClass.php',
            'Search'  => 'Search.php',
            'User'  => 'User.php'
        );
    
        static function loader($className) {
            $filename = Loader::PHP_CLASSES_ROOT.self::$account_nameClasses[$className];
    
            if(file_exists($filename)){
                require_once $filename;
            }else{
                return false;
            }
        }
    }
    
    spl_autoload_register(array(account_name_Loader, 'loader'));
    

    Of if the class names are used elsewhere you can create a function to build paths:

    class Loader {
        const PHP_CLASSES_ROOT = '/home/account_name/public_html/includes/php/';
    
        static $account_nameClasses = array(
            'DB' => 'DB.php',
            'Skin' => 'Skin.php',
            'API' => 'apiClass.php',
            'Search'  => 'Search.php',
            'User'  => 'User.php'
        );
    
        static function resolveClassPath($className) {
            return Loader::PHP_CLASSES_ROOT . $filename;
        }
    
        static function loader($className) {
            $filename = self::resolveClassPath($className);
    
            if(file_exists($filename)){
                require_once $filename;
            }else{
                return false;
            }
        }
    }
    
    spl_autoload_register(array(account_name_Loader, 'loader'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .php file that looks like this: foreach($stmt->fetchAll() as $array) { echo
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have php scripts that do things like register, login, upload. I would like
I have a live site that includes different php files depending on what page
I have a PHP class method which is using a static function from with
Does PHP have a method of having auto-generated class variables? I think I've seen
I have PHP configured so that magic quotes are on and register globals are
We have PHP 5.2.6 deployed to c:\php and in that folder there is the
I have php script that creates a temporary watermark image for users that are
On my bootstrap I don't have a class, it's a simple php file: I

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.