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 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
  • 1 View
  • 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

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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

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.