My ZF adventures take me to the Zend_Loader class today.

What is that, you ask? Zend_Loader provides methods for um, loading, files and classes in your web application. Delving into Zend/Loader.php reveals the following methods:

loadFile() – this is basically a fancy include statement. it takes in three parameters: a filename, directories to search (one or multiple — if blank, will search include path), and once, which tells it whether to do an include() or include_once(). the difference in those is that include_once() will only let you load a file once on a page, regardless of how many times it is called.

– determines whether a file can be read or not. this uses the fopen() function with a read parameter to get its answer

_securityCheck – this is a protected class, which means that only this class and ones that extend from it can access it. this method determines whether a filename is legit. it uses a fancy regular expression to check this: '/[^a-z0-9\/\\_.-]/i', which I’d like to come back to eventually and make sure I follow

_includeFile – this is also a protected class and is similar to loadFile(), but, this doesn’t allow a directory to be set. it does, like loadFile(), let you specify once.

loadClass() and autoload() – loads a specific class. it looks like autoload() calls loadClass() and thats about it, so not sure what the difference is.

registerAutoload() – automatically loads a class when it is called in the code (so you don’t have to).

So for example:

At the beginning of the bootstrapper file, we have the code:


$config = new Zend_Config_Ini('settings.ini', 'development');

By using registerAutoload(), I avoid having to write

Zend_Loader::loadClass('Zend_Config_Ini'); prior to using Zend_Config_Ini.

What happens if you leave this out? Chaos:

Fatal error: Class 'Zend_Config_Ini' not found in /home/content/.../html/indextest.php on line 14

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s