smarty
smarty copied to clipboard
PHP 8 migration - Warning: Undefined array key
Hi,
i was using php7.4 but i want to switch to php 8, but my codebase is crowded with a lot of smarty template files. and in my templates i use {$error} but in some cases php wont assign this var to template, and since its working in php7.4, it gives warning all over the pages in php8.. i think it will be very painfull to review all the templates and change them.. i need to do it in the smarty core...
any suggestions?
I think you want muteExpectedErrors()
https://www.smarty.net/docs/en/api.mute.expected.errors.tpl
actually when i set this var;
/** * PHP7 Compatibility mode * @var bool */ private $isMutingUndefinedOrNullWarnings = false;
it mutes the warnings, but i'm not sure if its the correct way, there must be a solution within the Smarty core (i.e while creating the template file isset() automatically added to parameters) ?
I tackled this with the method call below and it works like charm :)
$smarty->muteUndefinedOrNullWarnings()
Yep i'm using it too! :) at the end Smarty is a template engine, its acceptable to mute warnings i guess :)
@scottchiefbaker muteExpectedErrors has been dropped in v4 and did something else. muteUndefinedOrNullWarnings is the API method one would use to mute warning about undefined variables.
Thanks for the clarification. I have updated my side.
@wisskid I just checked the docs and there is no mention of the new method, or the deprecation on the old one. This should probably be remedied so we can direct users at the official documentation.
I also did not find any mention of muteUndefinedOrNullWarnings in the docs… I actually started implementing a custom error handler first, but then stumbled upon it in the core source code :)
would be super awesome to have a reference included in a docs section dedicated to porting templates to PHP 8.*