Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Although environment variable are not code specific, we can still benefit from using a package to work with these variable. This video will demonstrate the application we'll be working with and step through the basics of working with the phpdotenv package.
Autoloading Classes in PHP
Many developers writing object-oriented applications create one PHP source file per class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).
Since PHP 5, this is no longer necessary. The spl_autoload_register() function registers any number of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.
Composer has accepted the standard put out by the PHP-FIG (Framework Interop Group) of how autoloaders should work in PSR-4: Autoloading
Setting Environment Variables
There are many different ways to set/access environment variables.
- Through code
- On the system*
- The hosting company's dashboard such as AWS
- System wide /etc/environment
-
Apache virtual host (example of file located somewhere similar to /etc/apache2/sites-available*)
<VirtualHost host1> SetEnv SPECIAL_PATH /foo/bin ... </VirtualHost>
* try a google search for your particular setup
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up