From 6b748d24babc22718d619188173f77cb0f4200a4 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Tue, 25 Apr 2023 22:57:47 +0200 Subject: [PATCH] Trigger deprecation notice on unregistered static class methods as well. --- lexer/smarty_internal_templateparser.y | 3 +++ libs/sysplugins/smarty_internal_templateparser.php | 3 +++ .../TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php | 1 + 3 files changed, 7 insertions(+) diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y index 62049876..ffc85bc0 100644 --- a/lexer/smarty_internal_templateparser.y +++ b/lexer/smarty_internal_templateparser.y @@ -785,6 +785,9 @@ value(res) ::= ns1(c)DOUBLECOLON static_class_access(s). { if (isset($this->smarty->registered_classes[c])) { res = $this->smarty->registered_classes[c].'::'.s[0].s[1]; } else { + trigger_error('Using unregistered static method "' . c.'::'.s[0] . '" in a template is deprecated and will be ' . + 'removed in a future release. Use Smarty::registerClass to explicitly register ' . + 'a class for access.', E_USER_DEPRECATED); res = c.'::'.s[0].s[1]; } } else { diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index a2dd0d6f..c37d3c18 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -2425,6 +2425,9 @@ public static $yy_action = array( if (isset($this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor])) { $this->_retvalue = $this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor].'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1]; } else { + trigger_error('Using unregistered static method "' . $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0] . '" in a template is deprecated and will be ' . + 'removed in a future release. Use Smarty::registerClass to explicitly register ' . + 'a class for access.', E_USER_DEPRECATED); $this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1]; } } else { diff --git a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php index 24b2a62e..4855c0f0 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php @@ -223,6 +223,7 @@ class PhpFunctionTest extends PHPUnit_Smarty array('{$a = date("Y", $value)}{$a}', strtotime("01-01-2030"), 2030), array('{$a = PhpFunctionTest::sayHi($value)}{$a}', 'mario', 'hi mario'), array('{$a = pass($value)}{$a}', 'mario', 'mario'), + array('{$a = 1}{$b = Closure::fromCallable($value)}{$a}', 'strlen', 1), ); }