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 trialSean Flanagan
33,235 PointsWhere 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
20,660 PointsYou 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.
Sean Flanagan
33,235 PointsSean Flanagan
33,235 PointsThanks Sergey.
Sergey Podgornyy
20,660 PointsSergey Podgornyy
20,660 PointsYou are welcome