From dcf481b64f18d483fcdd248cb13093002a3daaec Mon Sep 17 00:00:00 2001 From: Thomas Punt Date: Fri, 8 Jan 2016 17:38:43 +0000 Subject: [PATCH] Modernise autoloading page git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@338442 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/autoload.xml | 53 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/language/oop5/autoload.xml b/language/oop5/autoload.xml index 9ecac63163..506a728ca3 100644 --- a/language/oop5/autoload.xml +++ b/language/oop5/autoload.xml @@ -9,29 +9,32 @@ at the beginning of each script (one for each class). - In PHP 5, this is no longer necessary. You may define an - __autoload function which is automatically - called in case you are trying to use a class/interface which hasn't been - defined yet. By calling this function the scripting engine is given - a last chance to load the class before PHP fails with an error. + In PHP 5, this is no longer necessary. The + spl_autoload_register function registers any number of + autloaders, 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. - spl_autoload_register provides a more flexible - alternative for autoloading classes. For this reason, using - __autoload is discouraged and may be deprecated or - removed in the future. + Whilst the __autoload function can also be used for + autoloading classes and interfaces, its preferred to use the + spl_autoload_register function. This is because it is + a more flexible alternative (enabling for any number of autoloaders to be + specified in the application, such as in third party libraries). For this + reason, using __autoload is discouraged and it may be + deprecated in the future. - Prior to 5.3.0, exceptions thrown in the __autoload function could not be - caught in the catch block and - would result in a fatal error. From 5.3.0+ exceptions thrown in the - __autoload function can be caught in the - catch block, with 1 provision. If throwing a custom exception, then - the custom exception class must be available. The __autoload function may - be used recursively to autoload the custom exception class. + Prior to PHP 5.3, exceptions thrown in the __autoload + function could not be caught in the + catch block and would result in + a fatal error. From PHP 5.3 and upwards, this is possible provided that if + a custom exception is thrown, then the custom exception class is available. + The __autoload function may be used recursively to + autoload the custom exception class. @@ -59,9 +62,9 @@ unserialize unserialize_callback_func spl_autoload - spl_autoload_register + __autoload