Re: __autoLoad php5 callback is being triggered for every class ?

From: Date: Fri, 29 Apr 2005 11:21:53 +0000
Subject: Re: __autoLoad php5 callback is being triggered for every class ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-214199@lists.php.net to get a copy of this message
* php@electroteque.org <php@electroteque.org>: > I'm experiencing some issues with autoLoad with pear packages. DB_Error is > contained within the DB.php, but my autoload method is trying to split the > underscores with forward slashes and then load. Supressing errors with @ > still doesnt work, its triggering a php error. Any ideas ? Sounds to me like you may need to do a quick call to file_exists() before trying to load it up. This may involve looping through the elements in your include_path to build the paths: // assuming $class = class requested $file = str_replace('_', '/', $class) . '.php'; $include_path = ini_get('include_path'); $paths = explode(':', $include_path); $final = ''; foreach ($paths as $path) { if (file_exists("$path/$file")) { $final = "$path/$file"; break; } } if (!empty($final)) { include_once $final; } -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.general (#214199) next »