1

I have a problem with hmlspecialchars giving an error in an OpenCart application. This is being logged in the error log but i have no idea which part of the application causes this since the code is being run on every request.

I tried catching exceptions on the function but i had nothing returned when the error occured. Will htmlspecialchars not be throwing any exceptions or is it possible that PHP is set to supress these? And in that case, could i change this at runtime?

try {
    $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
} catch (Exception $e) {
     $this->log->write($e->getMessage());
     $this->log->write($e->getTraceAsString());
}
  • What's the error? PHP functions normally don't throw exceptions – Mike B Mar 20 '14 at 14:44
  • htmlspecialchars(): Invalid multibyte sequence in argument in .../system/library/request.php on line 33 - As the file name suggests, this file is run on every request, but the error pops up pretty rarely, so it's hard for me to pinpoint what's causing this. – Carl Virdsten Mar 20 '14 at 14:47
  • http://stackoverflow.com/questions/3803951/htmlspecialchars-invalid-multibyte-sequence-in-argument – Mike B Mar 20 '14 at 14:48
  • Thank you. But my problem is that 99.5% of the site is properly encoded. I need a stacktrace so that i can find out which little part is causing this. – Carl Virdsten Mar 20 '14 at 14:50
  • You can set a custom error handler to capture the warning.. or something a little rougher like checking to see if the resulting $data is empty then logging the inputs. – Mike B Mar 20 '14 at 14:52

0 Answers0