Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarty is not compatible with PHP 8.0 #605

Closed
ildar-aim opened this issue Aug 11, 2020 · 19 comments
Closed

Smarty is not compatible with PHP 8.0 #605

ildar-aim opened this issue Aug 11, 2020 · 19 comments
Assignees

Comments

@ildar-aim
Copy link

https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING

For example, this patch causes a fatal error

diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl
index 1fbb6d3..291c3fa 100644
--- a/demo/templates/index.tpl
+++ b/demo/templates/index.tpl
@@ -1,6 +1,10 @@
 {config_load file="test.conf" section="setup"}
 {include file="header.tpl" title=foo}
 
+
+{if $smarty.const.TEST}
+{$smarty.const.TEST}
+{/if}
 <PRE>
 
 {* bold and title are read from the config file *}

Fatal error: Uncaught Error: Undefined constant "TEST" in public_html/smarty/demo/templates_c/234d0264d74c0efb651cf2c28d8975810c02182d_0.file.index.tpl.cache.php:35

Stack trace:
#0 public_html/smarty/demo/templates_c/234d0264d74c0efb651cf2c28d8975810c02182d_0.file.index.tpl.cache.php(35): constant('TEST')
#1 public_html/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_5f32594c42fb41_62206325(Object(Smarty_Internal_Template))
#2 public_html/smarty/libs/sysplugins/smarty_template_compiled.php(114): Smarty_Template_Resource_Base-&gt;getRenderedTemplateCode(Object(Smarty_Internal_Template))
#3 public_html/smarty/libs/sysplugins/smarty_internal_runtime_updatecache.php(38): Smarty_Template_Compiled-&gt;render(Object(Smarty_Internal_Template))
#4 public_html/smarty/libs/sysplugins/smarty_template_cached.php(143): Smarty_Internal_Runtime_UpdateCache-&gt;updateCache(Object(Smarty_Template_Cached), Object(Smarty_Internal_Template), f#5 public_html/smarty/libs/sysplugins/smarty_internal_template.php(211): Smarty_Template_Cached-&gt;render(Object(Smarty_Internal_Template), false)
#6 public_html/smarty/libs/sysplugins/smarty_internal_templatebase.php(232): Smarty_Internal_Template-&gt;render(false, 1)
#7 public_html/smarty/libs/sysplugins/smarty_internal_templatebase.php(134): Smarty_Internal_TemplateBase-&gt;_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 1)
#8 public_html/smarty/demo/index.php(36): Smarty_Internal_TemplateBase-&gt;display('index.tpl')
#9 {main}

due to
https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING

The code like this should not be used

<?php if (@constant('TEST')) {
echo @constant('TEST');?>

<?php }?>
@AnrDaemon
Copy link
Contributor

Can you please provide a patch as well? Use defined('CONSTANT') to detect the presence of it.

@wisskid
Copy link
Contributor

wisskid commented Aug 23, 2020

Planned availability of PHP8 is Nov 26 2020. We have some work to do here.

@AnrDaemon
Copy link
Contributor

Can we start by setting up Travis to run PHP8 tests?

Also, https://travis-ci.org/github/smarty-php/smarty/jobs/713094965 while we're at it.

@wisskid
Copy link
Contributor

wisskid commented Sep 4, 2020

I've set-up a vagrant box with debian 10 and compiled php8beta3 with mbstring. After removing the $errcontext variable everywhere (see #604, but completely removed it, and removed from unit tests as well) the remaining fails from the unit tests seem to be limited:

......................................................EEEF...   61 / 2393 (  2%)
.............................................................  122 / 2393 (  5%)
.....SSSSSS..................................................  183 / 2393 (  7%)
.............SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS  244 / 2393 ( 10%)
SSSSSSSSSSSS.................................................  305 / 2393 ( 12%)
..............F..............................................  366 / 2393 ( 15%)
......................................................R...R..  427 / 2393 ( 17%)
........................................................R...R  488 / 2393 ( 20%)
.............................................................  549 / 2393 ( 22%)
................S.S.S.........E..........................E..E  610 / 2393 ( 25%)
EE.EE.EE.....................................................  671 / 2393 ( 28%)
.............................................................  732 / 2393 ( 30%)
.............................................................  793 / 2393 ( 33%)
.............................................................  854 / 2393 ( 35%)
.............................................................  915 / 2393 ( 38%)
.............................................................  976 / 2393 ( 40%)
............................................................. 1037 / 2393 ( 43%)
............................................................. 1098 / 2393 ( 45%)
............................................................. 1159 / 2393 ( 48%)
............................................................. 1220 / 2393 ( 50%)
............................................................. 1281 / 2393 ( 53%)
...................................E........................E 1342 / 2393 ( 56%)
............................................................. 1403 / 2393 ( 58%)
............................................................. 1464 / 2393 ( 61%)
............................................................. 1525 / 2393 ( 63%)
............................................................. 1586 / 2393 ( 66%)
............................................................. 1647 / 2393 ( 68%)
..........................................................E.. 1708 / 2393 ( 71%)
...................R......................................... 1769 / 2393 ( 73%)
............................................................. 1830 / 2393 ( 76%)
............................................................. 1891 / 2393 ( 79%)
............................................................. 1952 / 2393 ( 81%)
............................................................. 2013 / 2393 ( 84%)
............................................................. 2074 / 2393 ( 86%)
............................................................. 2135 / 2393 ( 89%)
............................................................. 2196 / 2393 ( 91%)
.........E................................................... 2257 / 2393 ( 94%)
............................................................. 2318 / 2393 ( 96%)
......................................................R...... 2379 / 2393 ( 99%)
..............                                                2393 / 2393 (100%)

Time: 2.68 minutes, Memory: 32.00MB

There were 16 errors:

1) UndefinedTemplateVarTest::testE_NoticeDisabled
Undefined array key "foo"

/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/d6b0fd5b3e3e321065cf5ac52a6e7fb7c73228da_0.file.001_include.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:385
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/fa1c875f6451a656c3a14b230296e25b244759f7_0.file.001_main.tpl.php:25
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php:33

2) UndefinedTemplateVarTest::testE_NoticeDisabledTplObject_1
Undefined array key "foo"

/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/d6b0fd5b3e3e321065cf5ac52a6e7fb7c73228da_0.file.001_include.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:385
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/fa1c875f6451a656c3a14b230296e25b244759f7_0.file.001_main.tpl.php:25
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php:46

3) UndefinedTemplateVarTest::testE_NoticeDisabledTplObject_2
Undefined array key "foo"

/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/d6b0fd5b3e3e321065cf5ac52a6e7fb7c73228da_0.file.001_include.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:385
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/fa1c875f6451a656c3a14b230296e25b244759f7_0.file.001_main.tpl.php:25
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php:56

4) SecurityTest::testTrustedUri
SmartyException: {fetch} cannot read resource 'https://www.smarty.net/docs/en/preface.tpl'

/smarty/smarty/libs/plugins/function.fetch.php:196
/smarty/smarty/tests/UnitTests/SecurityTests/templates_c/d9ab7eaa83efe8c19a07555b9cfd08c53ea34a13_0.string.php:19
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SecurityTests/SecurityTest.php:371

5) ClearAllAssignBCTest::testSmarty2ClearAllAssignInSmarty
Undefined array key "foo"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php:38

6) ClearAllAssignTest::testClearAllAssignInTemplate
Undefined array key "blar"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php:51

7) ClearAllAssignTest::testClearAllAssignInData
Undefined array key "bar"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php:61

8) ClearAllAssignTest::testClearAllAssignInSmarty
Undefined array key "foo"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php:71

9) ClearAssignBCTest::testSmarty2ClearAssign
Undefined array key "blar"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php:38

10) ClearAssignBCTest::testSmarty2ArrayClearAssign
Undefined array key "foo"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php:45

11) ClearAssignTest::testClearAssign
Undefined array key "blar"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php:41

12) ClearAssignTest::testArrayClearAssign
Undefined array key "foo"

/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php:51

13) CompileForeachTest::testForeach with data set #6 ('{foreach item=x from=$foo}{$x...reach}', null, 'else', '', 6)
Undefined array key "foo"

/smarty/smarty/tests/UnitTests/TemplateSource/TagTests/Foreach/templates_c/1e8203e7f797131c6f9b778d81729d48af47a71c_0.file.testForeach_6.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php:50

14) CompileForeachTest::testForeach with data set #31 ('{foreach $foo as $x}{$x}{fore...reach}', null, 'else', '', 31)
Undefined array key "foo"

/smarty/smarty/tests/UnitTests/TemplateSource/TagTests/Foreach/templates_c/86c740f8ab8059c9a233fd62d9de76dac89315e4_0.file.testForeach_31.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php:50

15) PluginFunctionFetchTest::testFetchUri
SmartyException: {fetch} cannot read resource 'https://www.smarty.net/docs/en/preface.tpl'

/smarty/smarty/libs/plugins/function.fetch.php:196
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionFetchTest.php:37

16) ConstantsTest::testConstantsUndefined
Error: Undefined constant "MYCONSTANT2"

/smarty/smarty/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/templates_c/0256f03ee3c7feef478edf934160e395238b0231_0.string.php:18
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php:82

--

There were 2 failures:

1) UndefinedTemplateVarTest::testE_Notice
Failed asserting that exception of type "PHPUnit\Framework\Error\Warning" matches expected exception "PHPUnit_Framework_Error_Notice". Message was: "Undefined array key "foo"" at
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/d6b0fd5b3e3e321065cf5ac52a6e7fb7c73228da_0.file.001_include.tpl.php:24
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:385
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/fa1c875f6451a656c3a14b230296e25b244759f7_0.file.001_main.tpl.php:25
/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php:123
/smarty/smarty/libs/sysplugins/smarty_template_compiled.php:114
/smarty/smarty/libs/sysplugins/smarty_internal_template.php:216
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:232
/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php:116
/smarty/smarty/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php:70
/smarty/smarty/vendor/phpunit/phpunit/phpunit:53
.

2) ConfigVarTest::testConfigUndefinedNotice
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Undefined variable: foo'
+'Undefined variable $foo'

/smarty/smarty/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php:406

--

There were 6 risky tests:

1) FileResourceTest::testGetCompiledTimestampPrepare
This test did not perform any assertions

2) FileResourceTest::testMustCompileTouchedSourcePrepare
This test did not perform any assertions

3) PhpResourceTest::testIsCachedTouchedSourcePrepare
This test did not perform any assertions

4) PhpResourceTest::testSmartyIsCachedPrepare
This test did not perform any assertions

5) PluginFunctionHtmlImageTest::testFoo
This test did not perform any assertions

6) ScopeTest::testFunctionScope
This test did not perform any assertions

ERRORS!
Tests: 2393, Assertions: 3310, Errors: 16, Failures: 2, Skipped: 69, Risky: 6.

Mostly changes to the unit tests themselves.

@wisskid
Copy link
Contributor

wisskid commented Sep 4, 2020

Yes, many of the "undefined array key ..." errors are easily fixed: "A number of notices have been converted into warnings". We should just up the setErrorReporting to ~E_WARNING.

@AnrDaemon
Copy link
Contributor

Can we set the Travis first, so pull requests could start flowing?

@wisskid
Copy link
Contributor

wisskid commented Sep 10, 2020

Yes, but to re-enable it (I disabled php nightly recently) we'll have to fix the unit tests first, as they all fail now. I'll take a shot at it.

@wisskid
Copy link
Contributor

wisskid commented Sep 10, 2020

See #608

@caugner
Copy link
Contributor

caugner commented Oct 19, 2020

Yes, many of the "undefined array key ..." errors are easily fixed: "A number of notices have been converted into warnings". We should just up the setErrorReporting to ~E_WARNING.

@wisskid I wonder if the Smarty_Internal_Data->tpl_vars array couldn't instead be converted to a wrapper object (wrapping the array and implementing ArrayAccess) that returns null for non-existing items? This would avoid the E_WARNING for all cases where users rely on non-assigned vars to be null-ish, so we could still report other warnings.

For nested cases, an equivalent of the null-coalescing operator (?? / 7.0+) and/or the nullsafe operator (?-> / 8.0+) would be helpful to be usable inside Smarty templates, e.g.:

{if $object?.attribute?.nested}
{/if}

(which would not cause any warning if any of the hierarchy is not set/null)

@Bigbear7
Copy link

Bigbear7 commented Dec 8, 2020

Just switched over our test site running on Smarty 3.1.36 to PHP 8. The content is shown, no white screen. So application doesn't bail out. However the logs are filled with: Undefined array key "XXX". The vote for lifting that from notice to warning in PHP RFC Reclassifying engine warnings was 42 to 21... Any hope on fixing this besides changing errorreporting?

@AnrDaemon
Copy link
Contributor

Find where Smarty trap internal errors and see if you can amend for that. Though that would be a workaround at most.

@Bigbear7
Copy link

Well, a slightly quick & dirty fix is the following line of code when initialising smarty:
$smarty = new Smarty();
$smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE);

I have close to zero warnings today when running site on PHP 7.4 with Smarty, so besides muting out other relevant PHP 8 warnings, it feels a bit safe to do so. I also assume this function only affects error levels within Smarty, but I'll check.

@AnrDaemon
Copy link
Contributor

Seems so at first glance. Smarty::$error_reporting is used in conjunction with storing and restoring current reporting levels.

This was referenced Jan 5, 2021
@timmit-nl
Copy link

as the other issue is closed:

I recommend that the default modifier is changed to:

$output = '(($tmp = ' . $output . ' ?? null)===null||$tmp==='' ? (' . $param . ' ?? null) : $tmp)'; // edit by 2020.12.1 -- fixed PHP 8 (#617)

has support for more default options and those also can be unset. So it is the same fix the topic starter of #617 suggest only this is also working for the params:
if the array/object/value is empty or not set at all, this will work without any errors:

{$array.layer1.DT_KVERVAL|default: $array.DT_KVERVAL: ''}
(the multiple default params are undocumented, but existing in the original code)

we currently extend the template_plugin_modifiercompiler_default so we are not raising any errors on airbrake as it is also ignoring @.

It is NOT pre 7.0 supported as the ??(Null coalescing operator) is 7.0+ (https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op)

Maybe it is a good think to add some kind of legacy switch (maybe auto set in constructor) and diffentiate some code on that. So there is pre 7.0 support.

@ekonoval
Copy link

ekonoval commented Jan 6, 2021

Some sort of null coalesce support would be really great...
Cause refactoring stuff like this is really annoying without it.

<div class="class1 {$additionalBadgeClass}">

<div class="class1 {if isset($additionalBadgeClass)}$additionalBadgeClass{/if}">

Not supported unfortunately:
<div class="class1 {$additionalBadgeClass ?? ''}">

@timmit-nl
Copy link

Some sort of null coalesce support would be really great...
Cause refactoring stuff like this is really annoying without it.

<div class="class1 {$additionalBadgeClass}">

<div class="class1 {if isset($additionalBadgeClass)}$additionalBadgeClass{/if}">

Not supported unfortunately:
<div class="class1 {$additionalBadgeClass ?? ''}">

if you do:
{$additionalBadgeClass|default: ''}

and use the template_plugin_modifiercompiler_default with the change as suggested in my post. You can do it.

@ekonoval
Copy link

ekonoval commented Jan 6, 2021

Some sort of null coalesce support would be really great...
Cause refactoring stuff like this is really annoying without it.
<div class="class1 {$additionalBadgeClass}">
<div class="class1 {if isset($additionalBadgeClass)}$additionalBadgeClass{/if}">
Not supported unfortunately:
<div class="class1 {$additionalBadgeClass ?? ''}">

if you do:
{$additionalBadgeClass|default: ''}

and use the template_plugin_modifiercompiler_default with the change as suggested in my post. You can do it.

Thanks a lot for the tip! Has been working with smarty for several years but hadn't bumped in on this modifier previously. It seems to be the functionality I was looking for.

@wisskid
Copy link
Contributor

wisskid commented Jan 7, 2021

Constant problem was already fixed in #609 #613 I think. At least the unit tests now pass in feature/php8-support

@wisskid wisskid closed this as completed Jan 7, 2021
@wisskid
Copy link
Contributor

wisskid commented Jan 8, 2021

I've added a specific unit test for this case and it passes perfectly in PHP8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants