note 76985 added to function.include-once

From: Date: Wed, 08 Aug 2007 22:29:56 +0000
Subject: note 76985 added to function.include-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-129361@lists.php.net to get a copy of this message
If you are like me and make heavy use of the __autoload magic function, always set include paths so you can just instantiate your class, and have multiple locations and name schemes for your custom libraries then you might be frustrated by simple parse errors being supressed when using @include_once('lib.php'). The solution I came up with was: define('IN_PRODUCTION_ENV',FALSE); function __autoload($class){ $paths = array(); $paths[] = "{$class}_lib.php"; $paths[] = "{$class}_inc.php"; $paths[] = "{$class}.php"; if(IN_PRODUCTION_ENV){ foreach($paths as &$path){ if((@include_once $path) !== false){ return; }//if }//foreach }else{ // we are not in a production environment so we want to see all errors... $include_paths = explode(PATH_SEPARATOR,get_include_path()); foreach($include_paths as $include_path){ // go through each of the different class names... foreach($paths as $path){ // attach each class name to the include path... $include_file = $include_path.$path; if(file_exists($include_file)){ if((include_once $include_file) !== false){ return; }//if }//if }//foreach }//foreach }//if/else trigger_error("{$class} was not found",E_USER_ERROR); }//method Now, just make sure you define IN_PRODUCTION_ENV to true or false to get either the slower (with all parse errors shown) or the faster (just suppress everything) autoloading. Hope this helps someone else since it was annoying just having blank screens show up when I had a simple parse error. Thanks to flobee at gmail dot com for providing me with the epiphany on why pages were showing up blank...-Metagg ---- Server IP: 69.147.83.197 Probable Submitter: 208.110.159.65 ---- Manual Page -- http://www.php.net/manual/en/function.include-once.php Edit -- https://master.php.net/note/edit/76985 Del: integrated -- https://master.php.net/note/delete/76985/integrated Del: useless -- https://master.php.net/note/delete/76985/useless Del: bad code -- https://master.php.net/note/delete/76985/bad+code Del: spam -- https://master.php.net/note/delete/76985/spam Del: non-english -- https://master.php.net/note/delete/76985/non-english Del: in docs -- https://master.php.net/note/delete/76985/in+docs Del: other reasons-- https://master.php.net/note/delete/76985 Reject -- https://master.php.net/note/reject/76985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129361) next »