Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Building Websites with PHP Dependency Management Autoloading

Sean Flanagan
Sean Flanagan
33,235 Points

Where did the __DIR__ come from?

Hi.

I noticed that at 2 minutes 20 seconds this statement appeared

require '/vendor/autoload.php';

but on getcomposer.org, under Autoloading, I get this:

require __DIR__ . '/vendor/autoload.php';

I'm assuming that the change occurred since the video was published. Which of these should we use?

By the way I've used the first statement, which doesn't have the DIR.

1 Answer

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

You can read more about magic constants on php.net

__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.