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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:50:00+00:00 2026-05-15T10:50:00+00:00

I’ve never seen anything like this. File structure: somefolder/base.php includes/stuff.php includes/constants.php base.php: <?php require(../includes/stuff.php);

  • 0

I’ve never seen anything like this.

File structure:

  • somefolder/base.php
  • includes/stuff.php
  • includes/constants.php

base.php:

<?php require("../includes/stuff.php"); ?>

stuff.php:

<?php 
   require("constants.php"); 
   echo "Welcome to stuff.php";
?>

constants.php:

<?php echo "IMPORTANT CONSTANTS DEFINED HERE!";  ?>

Result:

Welcome to stuff.php

Why doesn’t it display the constant.php message?! I’ll tell you what isn’t the problem: it isn’t the php code.

I started off with some complex files where the constants file was actually DEFINE()-ing some constants and for some reason the only the first few constants were working. I ended up disabling all the extraneous code including the DEFINE()’s and just having echo statements and this problem still kept staring me in the face. And by the way how could some of the defined constants make it through but not any echo’s, regardless of the order of the code?

So I finally realized this was absurd and decided to just create some new files as a test. Those ones worked. Or maybe they didn’t, I forget. Anyway I have had some measure of success by creating new files and experimenting with moving them around and copying code from one file to another but there hardly seems to be any rhyme or reason to it.

Wow, this just in: I got the constants.php file working under a different name but when I changed it to constants.php it stopped working! I tried clearing the cache/opening in a different browser and restarting the server but none of it helps. I feel like either I or my computer is on drugs. Gaaaahh!!!


EDIT

Aha. I left out one very important piece of information it looks like. One file I didn’t mention.

  • somefolder/constants.php

That file was being included instead of the includes/constants.php. That’s why I wasn’t getting any missing file errors. That was totally confusing things! I expected that sub-includes happen before higher level includes so stuff.php would look for constants.php in it’s own directory but I guess base.php includes stuff.php and THEN base.php does the include specified in stuff.php which means the include is relative to base.php. So absolute paths is the solution after all.

Additional edit:

Very interesting. I was still puzzled why it worked before when I simply changed the name of includes/constants.php (to constanza.php for example). It looks like file inclusion isn’t so cut and dry. If there are two files with the same name it will prefer the one relative to the parent file doing the including. But if it has no choice it will do it relative to the child just fine.

  • 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-15T10:50:00+00:00Added an answer on May 15, 2026 at 10:50 am

    The path used in your includes are not relative to the file the includes are : they are relative to the include_path.

    Which means that using relative paths with includes/requires will generally not do what you expect it to…

    The solution that’s generally used is to **work with absolute paths** ; this way, you are sure what gets included.

    Of course, using absolute paths in your code is bad (it will work on one server, but not another, when your application is deployed to another path) ; so, the solution is to :

    • get the absolute path to the file you’re in
    • use that, in addition to a relative path to another file, to include that file.

    The full path to the file you’re in can be obtained with `__FILE__`.

    Which means the directory to the current file (the file that instruction is written in) can be obtained with dirname(__FILE__).

    After that, it’s only a matter of writing the correct paths.

    For example, in stuff.php, you’d use :

    require(dirname(__FILE__) . "/constants.php"); 
    

    While, in base.php , you’d use :

    require(dirname(__FILE__) . "/../includes/stuff.php");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your mapping looks OK to me at first sight. My… May 17, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer Finally found it. This function in my code (or rather… May 17, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer In applicationWillTerminate: and applicationDidEnterBackground:, save enough state to [NSUserDefaults standardUserDefaults]… May 17, 2026 at 2:23 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.