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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:05:46+00:00 2026-06-17T16:05:46+00:00

Possible Duplicate: relative path in require_once doesn’t work I have a project structure as

  • 0

Possible Duplicate:
relative path in require_once doesn’t work

I have a project structure as such:

ProjectName/
   src
     test
       TestClass.php
   tests
     TestTestClass.php

WhenI try and do require_once '/ProjectName/src/test/TestClass.php'; into tests/TestTestClass.php I get an error from PHP stating that: no such file or directory.

I have checked the spelling, I have checked everything. I cannot give it the full /home/userName/bla/bla path as I need to hand this off to some one else.

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-06-17T16:05:46+00:00Added an answer on June 17, 2026 at 4:05 pm

    This is expected behaviour. When you execute TestTestClass.php, your working directory is set to ProjectName/tests.

    It would be better to use ../src/test/TestClass.php.

    Your path is actually absolute, so you will be working straight from /, which is not what you’re expecting. If your include_path is set to your server’s directory root, then your code will work without the first /. If you don’t wish to rely on include_path or arbitrary levelling (with ..), you can always set an environment variable in your first file that defines the full path to your application root, then use that for all includes.

    For example, /ProjectName/index.php:

    define('APPPATH', __DIR__);
    

    .. and in /ProjectName/tests/TestTestClass.php:

    require_once APPPATH . '/src/test/TestClass.php';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Getting path relative to the current working directory? I have code in
Possible Duplicate: WPF Image to byte[] Relative to this I have a BitmapSource image
Possible Duplicate: Using a relative path in connection string for Access DB in C#
Possible Duplicate: nested relative positioned div needs to have a 100% height I haven't
Possible Duplicate: How to calculate relative path between 2 directory path? I need to
Possible Duplicate: How to construct a relative path in Java from two absolute paths
Possible Duplicate: SQL Express Connection string - Relative to application location I have a
Possible Duplicate: Absolute path & Relative Path This is a very basic question, but
Possible Duplicate: Variable doesn’t get returned from AJAX function I have this function: function
Possible Duplicate: Qt equivalent of PathAppend? Short story: does Qt 4 have an analog

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.