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

Some php function have error with registerPlugin #961

Open
Nightprince opened this issue Mar 26, 2024 · 11 comments
Open

Some php function have error with registerPlugin #961

Nightprince opened this issue Mar 26, 2024 · 11 comments

Comments

@Nightprince
Copy link

Nightprince commented Mar 26, 2024

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
Copy link
Contributor

wisskid commented Mar 26, 2024

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

@Nightprince
Copy link
Author

No, I don't need foreach.

@Nightprince
Copy link
Author

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
Copy link
Contributor

wisskid commented Mar 26, 2024

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

@Nightprince
Copy link
Author

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
Copy link
Author

I have listed some of functions:

  • key
  • ksort
  • krsort
  • natsort
  • natcasesort
  • asort
  • arsort
  • sort
  • rsort
  • usort
  • uasort
  • uksort
  • shuffle
  • array_walk
  • array_walk_recursive
  • end
  • prev
  • next
  • reset
  • current
  • extract
  • array_multisort
  • array_push
  • array_pop
  • array_shift
  • array_unshift
  • array_splice

@wisskid
Copy link
Contributor

wisskid commented Mar 27, 2024

@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.

@wisskid wisskid closed this as completed Mar 27, 2024
@Nightprince
Copy link
Author

@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
Copy link
Contributor

wisskid commented Mar 27, 2024

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

@wisskid
Copy link
Contributor

wisskid commented Apr 5, 2024

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

@wisskid wisskid reopened this Apr 5, 2024
@Nightprince
Copy link
Author

I suggest you add these as default in Smarty.

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

No branches or pull requests

2 participants