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 7081569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:56:13+00:00 2026-05-28T06:56:13+00:00

Trying to autoload classes from <root>/incl/classes folder. The problem is, when I call some

  • 0

Trying to autoload classes from <root>/incl/classes folder.

The problem is, when I call some class for ex. ip like that

        $ip= new ip();
        $ip=$ip->get();

PHP gives error message Notice: Undefined variable: path . But in fact file already exists

enter image description here

I’m declaring all various paths at the top of page.

define("ds", DIRECTORY_SEPARATOR);
$path = array();
$path['root'] = $_SERVER['DOCUMENT_ROOT'];
$path['common'] = $path['root'] . ds . "common";
$path['design'] = $path['root'] . ds . "design";
$path['contents'] = $path['root'] . ds . "contents";
$path['content_images'] = $path['root'] . ds . "content" . ds . "images";
$path['design_images'] = $path['root'] . ds . "design" . ds . "images";
$path['blocks'] = $path['contents'] . ds . "blocks";
$path['includes'] = $path['root'] . ds . "incl";
$path['pages'] = $path['contents'] . ds . "pages";
$path['classes'] = $path['includes'] . ds . "classes";

$files = glob("common" . ds . "*.php");
array_unshift($files, $path['common'] . ds . "settings.php", $path['common'] . ds . "db.php");
foreach ($files as $filename)
    require_once $filename;

//Auto loading classes
function __autoload($class_name) {
    if (file_exists($path['classes'] . ds . $class_name . '.php')) {
        require_once($path['classes']. ds . $class_name . '.php');
    } else {
        die($path['classes'] . ds . $class_name . '.php');
    }
}

For testing purposes added die($path['classes'] . ds . $class_name . '.php'); line. It outputs \ip.php. I wonder, why it doesn’t echo $path[‘classes’] even if I declared it before ?

  • 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-28T06:56:14+00:00Added an answer on May 28, 2026 at 6:56 am

    It’s a scoping issue. Your $path variable doesn’t exist in your autoload function. It is a global variable, and you need to explicitly “invite” it:

    function __autoload($class_name) {
        global $path;
    

    You should actually have gotten a notice about this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to autoload Classes from within a folder contained in the application itself.
Trying to honor a feature request from our customers, I'd like that my application,
My problem is that while trying to implement usage of the Autoload feature, I
Trying to get my css / C# functions to look like this: body {
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I'm trying to autoload a class within symfony 2. The class lives in vendor/lessc/lessc.inc.php
I'm trying to include specific 'admin view' files from within a folder structure. I'm
I'v been trying to get phpunit up and running but for some reason i'm
I am trying to autoload my PHP 5.3 namespaced classes eg. /JM Auth.php User.php
I'm new in Ext and I have a problem: I'm trying to fill extjs-grid

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.