Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problem with @functions & error_reporting

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
xtof
Smarty n00b


Joined: 21 Oct 2011
Posts: 2

PostPosted: Fri Oct 21, 2011 7:32 am    Post subject: Problem with @functions & error_reporting Reply with quote

Hi all,

not really a bug, but a problem I'm facing with smarty & error reporting.

Basically the default error handling methods of PHP will be by-passed when
E_WARNING errors happen on "error controlled" functions (eg @filemtime())

But I'm paranoiac and decided to consider E_WARNING as a fatal error.

ex :

Code:


error_reporting(0);

set_error_handler('my_error_handler',(E_ALL | E_STRICT) &~ E_NOTICE);

$x = @filemtime('/tmp/nonexistingfile');

exit;

function my_error_handler($errno, $msg, $file, $line, $context=false) {
   
   die("$errno : $msg");
   
}



Doing that way, many smarty methods will throw an error such a the one containing @filemtime() or @unlink()

Am I doing something wrong, or should Smarty try to avoid error controlled functions ?

Code:

if(file_exists($file)) $x = filemtime($file);


(Yes, that's a system call more...)

Thank your for reading,

Christophe.
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Fri Oct 21, 2011 7:44 am    Post subject: Reply with quote

have a look at Smarty::muteExpectedErrors().

Code:
file_exists($file);
// <- race condition. Other Process might've unlink()ed the file in between these two statements!
filemtime($file);


an besides that, file_exists() can be inferred by filemtime(). Dropping file_exists() is double as fast…
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
xtof
Smarty n00b


Joined: 21 Oct 2011
Posts: 2

PostPosted: Fri Oct 21, 2011 12:07 pm    Post subject: Reply with quote

Thank you rodneyrehm, I'll give a look at how muteExpectedErrors() works…

Kind regards,

Christophe.
Back to top
View user's profile Send private message
richardward
Smarty n00b


Joined: 27 Oct 2011
Posts: 3

PostPosted: Thu Oct 27, 2011 10:10 am    Post subject: Reply with quote

We have a similar policy (all errors are fatal during development).

Take a look at the man page for set_error_handler:

Quote:
... you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.


Our error handler looks a bit like:

Code:
function handleError($errno, $message, $errfile, $errline) {
   $error_reporting=error_reporting();
   if($error_reporting===0)
      return false; // programmer used @ to specify ignoring all errors
   if(!($error_reporting & $errno))
      return false; // programmer asked to ignore this error
   //... display stacktrace, etc
   die();
}


Hope that helps.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP