Skip to content

Instantly share code, notes, and snippets.

@AgelxNash
Created February 12, 2013 08:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AgelxNash/4760875 to your computer and use it in GitHub Desktop.
Save AgelxNash/4760875 to your computer and use it in GitHub Desktop.
Корректная обработка возможных ошибок при подключении файла из текущей директории.
<?php
/**
* Include once file
*
* @category validate
* @version 0.1
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
* @param string $file Файл который необходимо подключить в текущей папке
* @param boolean $ret Возвращать статус подключения файла или его ответ
* @return boolean Результат подключения файла
* @author Agel_Nash <Agel_Nash@xaker.ru>
*/
function inc_once($file,$ret=false){
$flag=false;
if(is_scalar($file) && file_exists($file) && is_readable($file)){
if(in_array((dirname(__FILE__).DIRECTORY_SEPARATOR.$file), get_included_files())){
//die('Файл уже был подключен ранее');
}else{
$tmp = include_once($file);
$flag = $ret ? $tmp : true;
unset($tmp);
}
}else{
//die('Нет файла или он не доступен для чтения');
}
return $flag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment