note 80750 added to language.oop5.autoload

From: Date: Wed, 30 Jan 2008 15:39:26 +0000
Subject: note 80750 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-135608@lists.php.net to get a copy of this message
Regardless of the situation you're in (developing a web-app or writing some code that may use someone else's web-app), always a good idea not to use __autoload() but instead write a differently-named function and register it as an autoloader: <?php function class_autoloader($c) { if(file_exists(dirname(__FILE__). "/classes/{$c}.php") && include_once(dirname(__FILE__). "/classes/{$c}.php")) { return true; } else { trigger_error("Could not load class '{$c}' from file '{$c}.php'", E_USER_WARNING); return false; } } spl_autoload_register("class_autoloader"); ?> Using spl_autoload_register(), the function class_autoloader() will now be used when classes are instantiated, just like __autoload() does, but without the potential conflict with other web-apps __autoload() function. ---- Server IP: 209.41.74.194 Probable Submitter: 63.117.33.114 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/80750 Del: integrated -- https://master.php.net/note/delete/80750/integrated Del: useless -- https://master.php.net/note/delete/80750/useless Del: bad code -- https://master.php.net/note/delete/80750/bad+code Del: spam -- https://master.php.net/note/delete/80750/spam Del: non-english -- https://master.php.net/note/delete/80750/non-english Del: in docs -- https://master.php.net/note/delete/80750/in+docs Del: other reasons-- https://master.php.net/note/delete/80750 Reject -- https://master.php.net/note/reject/80750 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135608) next »