mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
added basic examples for spl_autoload_register
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@325783 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
53cab0d4dc
commit
a3c111bffd
1 changed files with 26 additions and 1 deletions
|
@ -112,7 +112,32 @@
|
|||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title><function>spl_autoload_register</function> example</title>
|
||||
<title><function>spl_autoload_register</function> as a replacement for an <function>__autoload</function> function</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// function __autoload($class) {
|
||||
// include 'classes/' . $class . '.class.php';
|
||||
// }
|
||||
|
||||
function my_autoloader($class) {
|
||||
include 'classes/' . $class . '.class.php';
|
||||
}
|
||||
|
||||
spl_autoload_register('my_autoloader');
|
||||
|
||||
// Or, using an anonymous function as of PHP 5.3.0
|
||||
spl_autoload_register(function ($class) {
|
||||
include 'classes/' . $class . '.class.php';
|
||||
});
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title><function>spl_autoload_register</function> example where the class is not loaded</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
|
Loading…
Reference in a new issue