dirname(__FILE__) vs __DIR__, which is faster?

If you’re developing PHP software today but studied PHP based on old-ish manuals or manuals written by people who did, you might find a mix of calls to dirname(__FILE__) and __DIR__ and wonder what the difference is…

Past the fact that there is no real difference I could find in the data returned, it is interesting to note that __DIR__  is a MAGIC CONSTANT that exists in PHP since 5.3.0 and, as such, will certainly be faster most of the time. However, in the case of __DIR__, it is *always* faster, and considerably so.

Now, obviously, getting the current directory of the script will not be something that takes a very large chunk of the processing of your page, as you probably only call it once or twice at the beginning of your script (if calling it more than 2 times, it might make sense to just store it in a variable). However, when dealing with sites with millions of custom views (difficulting caching) every day, this might have some influence (I’m not saying it always will).

Read the full story by


How a Hosted LMS Promotes Online Corporate Learning Storyboards: What’s in a Number?
We are updating our Privacy Policy, so please make sure you take a minute to review it. As of May 25, 2018 your continued use of our services will be subject to this new Privacy Policy.
Review Privacy Policy OK