smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.23k stars 703 forks source link

Some php function have error with registerPlugin #961

Open Nightprince opened 4 months ago

Nightprince commented 4 months ago

reset(), key(), end() , ... have error when we use registerPlugin, error :

Error: ErrorException: reset(): Argument #1 ($array) must be passed by reference, value given in F:\laragon\www\CMS\vendor\smarty\smarty\src\Extension\CallbackWrapper.php:29

$this->registerPlugin(Smarty::PLUGIN_MODIFIER, 'end', 'end'); $this->registerPlugin(Smarty::PLUGIN_MODIFIER, 'key', 'key'); $this->registerPlugin(Smarty::PLUGIN_MODIFIER, 'reset', 'reset'); ...

wisskid commented 4 months ago

I don't think there's an easy fix for this. Can you change your template to use a foreach loop?

Nightprince commented 4 months ago

No, I don't need foreach.

Nightprince commented 4 months ago

What is advantage of using version 5 when all default functions of PHP are removed and must be added manually and there are problems with some functions.

wisskid commented 4 months ago

Smarty 5 adds support for ternary operator and the null coalescing operator, positional parameters for custom tags and a whole new extension architecture.

Nightprince commented 4 months ago

Well, they are useful if smarty has no problem with default PHP functions. In version 4, many people may have used many PHP functions in smarty that do not have their list. Finding these functions and also having problems in calling them is a very difficult issue.

Nightprince commented 4 months ago

I have listed some of functions:

wisskid commented 4 months ago

@Nightprince for a discussion about the decision to drop support for the use of unregistered callables in v5, see https://github.com/smarty-php/smarty/discussions/967. For the breaking change regarding passing variables by reference, I'll use https://github.com/smarty-php/smarty/issues/964 and close this issue.

Nightprince commented 4 months ago

@Nightprince for a discussion about the decision to drop support for the use of unregistered callables in v5, see #967. For the breaking change regarding passing variables by reference, I'll use #964 and close this issue.

Why should issue be closed when problem is not fixed?

wisskid commented 4 months ago

So we don't have 2 open issues for the same problem.

wisskid commented 4 months ago

Re-opening this, since it seems #964 is fixed (for Smarty > v4), but we cannot port that fix to Smarty v5.

Nightprince commented 4 months ago

I suggest you add these as default in Smarty.