That will try and find a file in these locations in order:
  /var/www/html/projects/include/db.inc
  ./db.inc
  /php/includes/db.inc

And will use the first one found.

I would  not suggest using ini_set() inside you're scripts to
adjust your paths.



Curt

Hey Curt, why do you suggest we don't use ini_set to adjust paths? I'm using it as part of my library autoloader - it may not be as efficient as changing the path directly but it seems to work well.



<?php /** * Used to load all class definitions. It temporarily adds directories * listed in $classDirs to the include path and tries to load the class * definition from the new temporary path. Path resets to original * after failure / success. * * @param string The name of the class that you want to instanciate. * This should use PEAR-style class names, e.g. * Directory_Subdir_File * @return object|void */ function __autoload($class) { if (empty($class) || strpos($class, '://')) { // Zend engine can't throw exceptions in __autoload() trigger_error('Cannot get class file', E_USER_WARNING); return; }

  if (!defined('PATH_SEPARATOR')) {
    if (strstr(PHP_OS, 'WIN')) {
      define('PATH_SEPARATOR', ';');
    } else {
      define('PATH_SEPARATOR', ':');
    }
  }

  static $origPath = null;
  if (is_null($origPath)) {
    $origPath = ini_get('include_path');
  }

  static $newPath = null;
  if (is_null($newPath)) {
    $cur       = dirname(__FILE__ . DIRECTORY_SEPARATOR);
    $classDirs = array($cur);
    $aryPath   = explode(PATH_SEPARATOR, $origPath);
    $aryPath   = array_merge($aryPath, $classDirs);
    $newPath   = implode(PATH_SEPARATOR, $aryPath);
  }

  // Do PEAR-like file inclusion
  $class = str_replace('_', DIRECTORY_SEPARATOR, $class);
  ini_set('include_path', $newPath);
  include_once ($class . ".php");
  if (!class_exists($class)) {
    trigger_error("No class definition for $class found in library",
                  E_USER_ERROR);
  }
  ini_set('include_path', $origPath);
}


?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to