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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:28:28+00:00 2026-05-30T06:28:28+00:00

Is it a sence to do something like $dir = realpath(dirname(__FILE__)); // or for

  • 0

Is it a sence to do something like

 $dir = realpath(dirname(__FILE__));
 // or for php 5.3+:
 $dir = realpath(__DIR__)

Or magic constants like DIR and FILE always returns absolute path, so realpath is redundant?

  • 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-30T06:28:29+00:00Added an answer on May 30, 2026 at 6:28 am

    You don’t need realpath().

    The documentation of __FILE__:

    The full path and filename of the file. If used inside an include, the
    name of the included file is returned. Since PHP 4.0.2, __FILE__
    always contains an absolute path with symlinks resolved whereas in
    older versions it contained relative path under some circumstances.

    So __FILE__ returns an absolute path => realpath() unnecessary

    And if you use __DIR__:

    The directory of the file. If used inside an include, the directory of
    the included file is returned. This is equivalent to
    dirname(__FILE__)
    . This directory name does not have a trailing slash
    unless it is the root directory. (Added in PHP 5.3.0.)

    __DIR__ also returns an absolute path because dirname() doesn’t cut off the absolute part of the path of __FILE__ => realpath() unnecessary

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

Sidebar

Related Questions

Can I do something like working-dir=file:${user.home}/some-directory within my .properties file? I am using ResourceBundle
So i wanna do something like this in php. If i have a year
Here's a snippet of my echo command: echo 'onclick=derp(',$url,$image_dir,$file,')' It currently outputs something like
Hey, I'm trying to do something like this: <?php class MySmarty extends Smarty {
It makes sense that something like an operating system would be written in C.
Does something like this make any sense at all in Java? class A<T extends
I need something simple like date , but in seconds since 1970 instead of
When I call a static method like: Something.action(); Since a instance isn't created how
I would like to skin a wpf default checkbox to something custom. Since it
To generate dependency files I can use something like this to generate dependency files:

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.