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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:21:49+00:00 2026-06-14T20:21:49+00:00

I have a directory/file tree as follows: index.php /frame/main_class.php /frame/func/function_1.php /frame/func/function_1.php /cfg/config.php //index.php require(‘frame/main_class.php’);

  • 0

I have a directory/file tree as follows:

index.php

/frame/main_class.php
/frame/func/function_1.php
/frame/func/function_1.php
/cfg/config.php

//index.php

require('frame/main_class.php');
new main_class;

//frame/main_class.php

class main_class{
    public function __construct(){
        require('func/function_1.php');
        require('func/function_2.php');
        require('cfg/config.php');
    }
}

The weird part is that it works. Maybe it is late and I am having a dumb-moment, but shouldn’t “require(‘cfg/config’);” be written “require(‘../cfg/config.php’);” ?

And if it is using the root of index.php, then “require(‘func/function_1.php’);” shouldn’t work, right?

I have quadruple checked the remote server thinking that maybe there was a stray file or two… there isn’t.
How can the two require statements have a different base path…..?

Does anyone know of a code snippet that could cause this to happen? I am working with some $_SERVER variables but I don’t appear to be changing any of them….!?


“Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include will finally check in the calling script’s own directory and the current working directory before failing.” Explicitly saying include dirname(__FILE__) . '/path/to/file.php';avoids this confusion. – DCoder

Link to PHP Manual on “dirname”.

  • 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-06-14T20:21:50+00:00Added an answer on June 14, 2026 at 8:21 pm

    The PHP engine will look for the requested files in the current directory, but it will also look for them in the list of paths defined in INCLUDE_PATH. If the include path lists the path from where your script is running then the given code will work. If not then it wont.

    For that reason amongst others it’s not a good idea to rely on the include path to resolve the path of included files. You should give the full path instead.

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

Sidebar

Related Questions

I have this piece of HTML <div id=fileTreeInviati> <ul class=php-file-tree> <li class=pft-directory> <a href=#
I have a file index.php in root directory: <?php require_once ./include/common.php; ?> and file
I have a directory tree that I need to process as follows: I have
I have a manifest file that looks as follows: # director.js //= require jquery
I am getting following errors. libxml/tree.h no such file or directory I have already
Zend framework i have directory tree as following with robots.txt file, but when i
So I have this class: http://pastebin.com/EwXFwuZz And this directory tree: http://s14.directupload.net/file/d/3099/uskko5mo_png.htm And I'm working
I'm confused with file moving under python. Under windows commandline, if i have directory
I have a JTree which contains file/directory, i want to get a list which
I have a directory path stored in a text file, and I need to

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.