disable smarty notice
Asked Answered
C

3

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!

Cryoscopy answered 22/7, 2011 at 11:8 Comment(0)
P
9

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

Just set

$smarty->error_reporting = E_ALL & ~E_NOTICE;
Physicist answered 22/7, 2011 at 11:38 Comment(3)
And is it possible to disable just that undefined var. ?Cryoscopy
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}..Physicist
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.Aniline
D
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.

Dimaggio answered 5/12, 2012 at 9:25 Comment(0)
S
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

Scaleboard answered 26/1, 2022 at 8:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.