note 62723 added to language.oop5.autoload

From: Date: Wed, 08 Mar 2006 08:55:45 +0000
Subject: note 62723 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-105031@lists.php.net to get a copy of this message
An issue I've had with using the __autoload function is getting it into the application. You have to have the function included in every topmost script. This is a pain if the entire application is OOP and an "app" can be just a component of another "app". A solution I've found is to use php.ini's auto_prepend_file setting. Mine is set to ... auto_prepend_file = auto_loader.php The auto_loader.php script contains a single function. The __autoload() function. The include_dir path IS examined to find this file, so you can just put it with the rest of your includable files. A useful additional facility here is that you could log which classes are used by a script at runtime. Very useful if you have object factories and can't know the load at design time. Also, assigning the uncaught exception handler and the error handlers in this file means your entire site WILL have some global protection without you having to deal with it on a script by script basis. If you do not have access to the PHP.INI file, or you are running on a shared server, you may not be able to set this property. In those cases, you may be able to set the value using .htaccess. (NOTE: UNTESTED as I don't use Apache). <IfModule mod_php5.c> php_value auto_prepend_file "auto_loader.php" </IfModule> You COULD therefore have a different set of rules per subdomain (if you have multiple subdomains, say, live, test, beta, devel) or whatever takes your fancy. For more details on this see the "Description of core php.ini directives" (http://www.php.net/manual/en/ini.core.php) ---- Server IP: 66.163.161.117 Probable Submitter: 83.104.121.66 (proxied: 1.1 BANDEXCH) ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- http://master.php.net/note/edit/62723 Del: integrated -- http://master.php.net/note/delete/62723/integrated Del: useless -- http://master.php.net/note/delete/62723/useless Del: bad code -- http://master.php.net/note/delete/62723/bad+code Del: spam -- http://master.php.net/note/delete/62723/spam Del: non-english -- http://master.php.net/note/delete/62723/non-english Del: in docs -- http://master.php.net/note/delete/62723/in+docs Del: other reasons-- http://master.php.net/note/delete/62723 Reject -- http://master.php.net/note/reject/62723 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105031) next »