\Zend_Loader

Static methods for loading classes and files.

Summary

Methods
Properties
Constants
loadClass()
loadFile()
isReadable()
autoload()
registerAutoload()
No public properties found
No constants found
_securityCheck()
_includeFile()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

loadClass()

loadClass(string  $class, string|array  $dirs = null) : void

Loads a class from a PHP file. The filename must be formatted as "$class.php".

If $dirs is a string or an array, it will search the directories in the order supplied, and attempt to load the first matching file.

If $dirs is null, it will split the class name at underscores to generate a path hierarchy (e.g., "Zend_Example_Class" will map to "Zend/Example/Class.php").

If the file was not found in the $dirs, or if no $dirs were specified, it will attempt to load it from PHP's include_path.

Parameters

string $class
  • The full class name of a Zend component.
string|array $dirs
  • OPTIONAL Either a path or an array of paths to search.

Throws

\Zend_Exception

loadFile()

loadFile(string  $filename, string|array  $dirs = null, boolean  $once = false) : boolean

Loads a PHP file. This is a wrapper for PHP's include() function.

$filename must be the complete filename, including any extension such as ".php". Note that a security check is performed that does not permit extended characters in the filename. This method is intended for loading Zend Framework files.

If $dirs is a string or an array, it will search the directories in the order supplied, and attempt to load the first matching file.

If the file was not found in the $dirs, or if no $dirs were specified, it will attempt to load it from PHP's include_path.

If $once is TRUE, it will use include_once() instead of include().

Parameters

string $filename
string|array $dirs
  • OPTIONAL either a path or array of paths to search.
boolean $once

Throws

\Zend_Exception

Returns

boolean

isReadable()

isReadable(string  $filename) : boolean

Returns TRUE if the $filename is readable, or FALSE otherwise.

This function uses the PHP include_path, where PHP's is_readable() does not.

Note from ZF-2900: If you use custom error handler, please check whether return value from error_reporting() is zero or not. At mark of fopen() can not suppress warning if the handler is used.

Parameters

string $filename

Returns

boolean

autoload()

autoload(string  $class) : string|false

spl_autoload() suitable implementation for supporting class autoloading.

Attach to spl_autoload() using the following: spl_autoload_register(array('Zend_Loader', 'autoload'));

Parameters

string $class

Returns

string|false —

Class name on success; false on failure

registerAutoload()

registerAutoload(string  $class = 'Zend_Loader', boolean  $enabled = true) : void

Register {@link autoload()} with spl_autoload()

Parameters

string $class

(optional)

boolean $enabled

(optional)

Throws

\Zend_Exception

if spl_autoload() is not found or if the specified class does not have an autoload() method.

_securityCheck()

_securityCheck(string  $filename) : void

Ensure that filename does not contain exploits

Parameters

string $filename

Throws

\Zend_Exception

_includeFile()

_includeFile(string  $filespec, boolean  $once = false) : boolean

Attempt to include() the file.

include() is not prefixed with the @ operator because if the file is loaded and contains a parse error, execution will halt silently and this is difficult to debug.

Always set display_errors = Off on production servers!

Parameters

string $filespec
boolean $once

Returns

boolean