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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:26:55+00:00 2026-06-17T12:26:55+00:00

I’m using symfony and trying to reference a file that’s in a parent directory

  • 0

I’m using symfony and trying to reference a file that’s in a parent directory like so:

require_once('../MyClass.class.php');

It doesn’t seem to be working though it keeps saying it can’t find the file when I run the task. I tried the same code on my personal WAMP server (as opposed to going through this server) and that doesn’t use symfony and it worked fine.

I’m not sure why symfony can’t find it?

Thanks

  • 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-17T12:26:55+00:00Added an answer on June 17, 2026 at 12:26 pm

    When you include a relative path, the path is relative to the “top-level” script – that is, the entry point to the application – rather than the script currently being executed.

    When dealing with frameworks, the entry point is often a file at the top of your web root called index.php. For this example, we’ll assume this file is ~/application/index.php.

    Your index.php file will necessarily include files from other parts of your framework, and it’s in one of these that you’re likely attempting to perform your include. Lets say that you’re attempting the include from a controller file. We’ll give it the filename ~/application/controllers/example.php.

    Now, what you think is happening when you do include "../MyClass.class.php" is that you think that the filename will be one level above the script that’s currently executing – i.e. you think that since you’re in ~/application/controllers/example.php, the parent directory will be ~/application/controllers, so you’ll include ~/application/MyClass.class.php.

    What will actually happen, is the relative path will be determined based on the location of the entry point, ~/application/index.php, so the parent directory will be ~/, and PHP will attempt to include the file ~/MyClass.class.php, which doesn’t exist.

    I don’t know Symfony, so I don’t know how it’s autoloader works, but you should be able to call a framework function to load your class for you. If you really must include the file manually, then you need to include the file relative to the index.php file. Most frameworks have constants (e.g. BASEDIR) that you can use to easily generate an absolute path.

    There are also two PHP-defined constants you can use for this:

    • __FILE__ will give the script-name for the currently executing script (not the main/top-level one as above), so you can use dirname(__FILE__) to get the current directory, or something like dirname(dirname(__FILE__)) to get the parent directory.
    • __DIR__ (for PHP >= 5.3.0) will give you the directory of the currently executing script, so you can use dirname(__DIR__) to get the parent directory.

    Again, your framework can likely handle this for you, but it’s good to know for when you’re dealing with non-framework scripts.

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.