Created
February 12, 2013 08:03
-
-
Save AgelxNash/4760875 to your computer and use it in GitHub Desktop.
Корректная обработка возможных ошибок при подключении файла из текущей директории.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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