8

I would like to disable smarty-s notices.

This exactly:

Notice: Undefined variable: xy

Because I know that some variables are undefined and in some cases I don't even want to define them.

BUT I don't want to disable other PHP notices.

Thanks for help!

3 Answers3

9

You should use this: http://www.smarty.net/docs/en/variable.error.reporting.tpl

Just set

$smarty->error_reporting = E_ALL & ~E_NOTICE;
Johan
  • 1,958
  • 11
  • 20
  • And is it possible to disable just that undefined var. ? –  Jul 22 '11 at 11:45
  • 2
    I guess you could set up a custom error handler for that.. Would be a bit overkill though. I always use {if isset($xy) && $xy == "foo"}do it{/if}.. – Johan Jul 22 '11 at 11:51
  • Be warned that this will also disable all notices for all your smarty plugins and any code they will execute. So this means your own error_reporting setting will get overwritten for Smarty and ALL code that is executed by it. I ended up having to remove this setting for it messed up my own error_reporting settings. – Maurice Apr 13 '12 at 07:14
3

You should make your checks on the variables and make sure they are defined and set before using. Removing the Notices and Warnings enhance the performance of your application.

When your application or website is published you should add the following condition to avoid errors from appearing to your customers:

error_reporting(E_ERROR || E_WARNING);

Only warning and Errors will appear.

Echilon
  • 10,064
  • 33
  • 131
  • 217
2

Since Smarty4 there is a new method:

    $smarty->setErrorReporting(E_ALL & ~E_NOTICE);
    $smarty->muteUndefinedOrNullWarnings();

See https://github.com/smarty-php/smarty/blob/v4.0.0/CHANGELOG.md

Wolfgang Blessen
  • 900
  • 10
  • 29