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:
Peter Cowburn 2012-05-22 20:52:05 +00:00
parent 53cab0d4dc
commit a3c111bffd

View file

@ -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