Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 18829 программистов и 1635 роботов. Сейчас ищут 1747 программистов ...
Checking if a driver can be loaded
Вернуться к: Recommendations
In driver-based packages you should check if the driver exists before loading it. A simple file_exists() does not work since it does not check the include path. fopen()'s third parameter does that, so we use it.
<?php
$driver = 'SomeDriver';
$class = 'My_Package_Driver_' . $driver;
$file = str_replace('_', '/', $class) . '.php';
//check if it exists and can be loaded
if (!@fclose(@fopen($file, 'r', true))) {
throw new My_Package_Driver_Exception(
'Driver ' . $driver . ' cannot be loaded.'
);
}
//continue with including the driver
require_once $file;
//...
?>
Вернуться к: Recommendations