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

Re-add support for implode, substr and json_encode #939

Closed
wisskid opened this issue Feb 24, 2024 · 3 comments · Fixed by #940
Closed

Re-add support for implode, substr and json_encode #939

wisskid opened this issue Feb 24, 2024 · 3 comments · Fixed by #940
Milestone

Comments

@wisskid
Copy link
Contributor

wisskid commented Feb 24, 2024

v4 deprecates and v5 drops support for many native php functions.
implode, substr and json_encode are commonly used and it might be useful to support them.

@wisskid wisskid added this to the 5.0 milestone Feb 24, 2024
@wisskid
Copy link
Contributor Author

wisskid commented Feb 24, 2024

There is a problem with implode. Using implode (or join) as a modifier in templates (prior to Smarty v5) (on PHP8), has to be done as follows: <td class="{' '|implode:$classes|escape}">, since passing the separator after the array is no longer supported in PHP.

As a modifier, this seems silly. It would be more intuitive to flip the arguments, in the way Twig does it: {{ [1, 2, 3]|join('|') }}. But we cannot just flip the arguments. We could detect argument types and throw a deprecation warning.

@wisskid
Copy link
Contributor Author

wisskid commented Feb 25, 2024

It seems Smarty v5 also supports strlen, time, count, is_array and in_array as functions. (They are implemented as FunctionHandlers.) This is undocumented.

@wisskid
Copy link
Contributor Author

wisskid commented Feb 25, 2024

Smarty also supports explode. It's undocumented, but it has been in the unit tests. However, the parameter order is weird and we cannot auto-fix it, since both parameters are strings. I propose to deprecate explode and promote split with the parameters reversed.
For consistency, this would also mean we should implement join in favor of implode.

wisskid added a commit that referenced this issue Feb 26, 2024
…#940)

* Implemented support for substr, implode and json_encode as modifiers. Fixes #939
* Added split and join in favor of explode and implode modifiers.
* Documented all available modifiers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant