diff --git a/changelog/996.md b/changelog/996.md new file mode 100644 index 000000000..3735bcc73 --- /dev/null +++ b/changelog/996.md @@ -0,0 +1 @@ +- Prevent deprecation notices during compilation in PHP8.3 [#996](https://github.com/smarty-php/smarty/issues/996) diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php index 23984151c..b775abba0 100644 --- a/src/Compiler/Template.php +++ b/src/Compiler/Template.php @@ -680,7 +680,8 @@ public function getPluginFromDefaultHandler($tag, $plugin_type) { * * @return string */ - public function appendCode($left, $right) { + public function appendCode(string $left, string $right): string + { if (preg_match('/\s*\?>\s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) { $left = preg_replace('/\s*\?>\s?$/D', "\n", $left); $left .= preg_replace('/^<\?php\s+/', '', $right); @@ -1056,7 +1057,7 @@ public function getPrefixCode() { $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); $this->prefixCodeStack[] = []; foreach ($prefixArray as $c) { - $code = $this->appendCode($code, $c); + $code = $this->appendCode($code, (string) $c); } $this->prefix_code = []; return $code; diff --git a/src/ParseTree/Dq.php b/src/ParseTree/Dq.php index 27c3db9f3..b5fca3b40 100644 --- a/src/ParseTree/Dq.php +++ b/src/ParseTree/Dq.php @@ -47,18 +47,18 @@ public function append_subtree(\Smarty\Parser\TemplateParser $parser, Base $subt if ($subtree instanceof Code) { $this->subtrees[ $last_subtree ]->data = $parser->compiler->appendCode( - $this->subtrees[ $last_subtree ]->data, + (string) $this->subtrees[ $last_subtree ]->data, 'data . ';?>' ); } elseif ($subtree instanceof DqContent) { $this->subtrees[ $last_subtree ]->data = $parser->compiler->appendCode( - $this->subtrees[ $last_subtree ]->data, + (string) $this->subtrees[ $last_subtree ]->data, 'data . '";?>' ); } else { $this->subtrees[ $last_subtree ]->data = - $parser->compiler->appendCode($this->subtrees[ $last_subtree ]->data, $subtree->data); + $parser->compiler->appendCode((string) $this->subtrees[ $last_subtree ]->data, (string) $subtree->data); } } else { $this->subtrees[] = $subtree; diff --git a/src/ParseTree/Tag.php b/src/ParseTree/Tag.php index f4bdee25e..05237f2de 100644 --- a/src/ParseTree/Tag.php +++ b/src/ParseTree/Tag.php @@ -62,9 +62,9 @@ public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) public function assign_to_var(\Smarty\Parser\TemplateParser $parser) { $var = $parser->compiler->getNewPrefixVariable(); - $tmp = $parser->compiler->appendCode('', $this->data); + $tmp = $parser->compiler->appendCode('', (string) $this->data); $tmp = $parser->compiler->appendCode($tmp, ""); - $parser->compiler->appendPrefixCode((string) $tmp); + $parser->compiler->appendPrefixCode($tmp); return $var; } } diff --git a/src/ParseTree/Template.php b/src/ParseTree/Template.php index 470963924..ce802a0f4 100644 --- a/src/ParseTree/Template.php +++ b/src/ParseTree/Template.php @@ -114,7 +114,7 @@ public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) break; case 'tag': foreach ($chunk['subtrees'] as $subtree) { - $text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser)); + $text = $parser->compiler->appendCode($text, (string) $subtree->to_smarty_php($parser)); } $code .= $text; break; diff --git a/src/Parser/TemplateParser.php b/src/Parser/TemplateParser.php index 12d9b6c5a..1e087c555 100644 --- a/src/Parser/TemplateParser.php +++ b/src/Parser/TemplateParser.php @@ -2536,7 +2536,7 @@ public function yy_r100(){ // line 806 "src/Parser/TemplateParser.y" public function yy_r101(){ $prefixVar = $this->compiler->getNewPrefixVariable(); - $tmp = $this->compiler->appendCode('', $this->yystack[$this->yyidx + 0]->minor); + $tmp = $this->compiler->appendCode('', (string) $this->yystack[$this->yyidx + 0]->minor); $this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "")); $this->_retvalue = $prefixVar; } diff --git a/src/Parser/TemplateParser.y b/src/Parser/TemplateParser.y index d01a42af3..f1e3c35ef 100644 --- a/src/Parser/TemplateParser.y +++ b/src/Parser/TemplateParser.y @@ -805,7 +805,7 @@ value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). { // Smarty tag value(res) ::= smartytag(st). { $prefixVar = $this->compiler->getNewPrefixVariable(); - $tmp = $this->compiler->appendCode('', st); + $tmp = $this->compiler->appendCode('', (string) st); $this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "")); res = $prefixVar; }