From 8eced58ba0eeb8c7ab48a3deb0f480d4dd20d8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garc=C3=ADa?= Date: Mon, 14 Jul 2014 19:16:28 +0200 Subject: [PATCH 1/3] Removed @ operator from dol_include_once Adding @ operator to include_once makes include errors untraceable, it shouldn't be there. Errors must be thrown so that we notice them. It is PHP configuration's choice to decide wether to log them or print them. --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b1f11590bdc..78326ee3bb7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -243,9 +243,9 @@ function dol_include_once($relpath, $classname='') global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var'] if (! empty($classname) && ! class_exists($classname)) { - return @include dol_buildpath($relpath); // Remove @ to find error into php log file if you have problems + return include dol_buildpath($relpath); } else { - return @include_once dol_buildpath($relpath); // Remove @ to find error into php log file if you have problems + return include_once dol_buildpath($relpath); } } From ad4512cb24de7df7625f43896225c8aa8f63b0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Tue, 15 Jul 2014 17:18:41 +0200 Subject: [PATCH 2/3] Avoiding include in case of unexisting file --- htdocs/core/lib/functions.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 78326ee3bb7..eb2cc15de15 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -236,11 +236,15 @@ function dol_getprefix() * * @param string $relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...) * @param string $classname Class name - * @return int false if include fails. + * @return bool */ function dol_include_once($relpath, $classname='') { - global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var'] + + if (!file_exists($relpath)) { + dol_syslog('functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_ERR); + return false; + } if (! empty($classname) && ! class_exists($classname)) { return include dol_buildpath($relpath); From bcafa2c79060ef4ab9b893cb60d102949214f530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Thu, 17 Jul 2014 21:44:59 +0200 Subject: [PATCH 3/3] Corrected file_exists check and little refactor --- htdocs/core/lib/functions.lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index eb2cc15de15..e91ee751727 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -240,16 +240,17 @@ function dol_getprefix() */ function dol_include_once($relpath, $classname='') { + $fullpath = dol_buildpath($relpath); - if (!file_exists($relpath)) { + if (!file_exists($fullpath)) { dol_syslog('functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_ERR); return false; } if (! empty($classname) && ! class_exists($classname)) { - return include dol_buildpath($relpath); + return include $fullpath; } else { - return include_once dol_buildpath($relpath); + return include_once $fullpath; } }