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

Using PHP functions and static class methods in expressions now also triggers a deprecation notice #880

Merged
merged 10 commits into from
Mar 18, 2024

Conversation

wisskid
Copy link
Contributor

@wisskid wisskid commented Apr 25, 2023

... because we will drop support for this in the next major release

Fixes #813

@wisskid wisskid changed the title Using PHP functions in expressions now also triggers a deprecation notice Using PHP functions and static class methods in expressions now also triggers a deprecation notice Apr 25, 2023
@vojtasvoboda
Copy link

Just a quick question, the following code will be supported in the next version of Smarty or not?

{foreach item=column from=range('A', 'Z')}
    ...
{/foreach}

Works with Smarty 4.3.4.

Thanks

@wisskid
Copy link
Contributor Author

wisskid commented Nov 20, 2023

Just a quick question, the following code will be supported in the next version of Smarty or not?

{foreach item=column from=range('A', 'Z')}
    ...
{/foreach}

Yes, Smarty 5 still supports the 'old' foreach syntax, @vojtasvoboda .

@vojtasvoboda
Copy link

vojtasvoboda commented Nov 20, 2023

The question was about calling the native PHP function range() (and also about other native PHP functions), sorry for the incomplete description :-) @wisskid

{foreach range('A', 'Z'} as $column}
    ...
{/foreach}

@wisskid
Copy link
Contributor Author

wisskid commented Nov 20, 2023

The question was about calling the native PHP function range() (and also about other native PHP functions), sorry for the incomplete description :-) @wisskid

{foreach range('A', 'Z'} as $column}
    ...
{/foreach}

Well, my answer wasn't very complete either... :-)
The range function is currently not implemented in v5.0.0-rc2 so it would have to be added as a custom extension. But if you feel that it is important, I would be open to add it to the DefaultExtension set. @vojtasvoboda

@wisskid wisskid changed the base branch from master to support/4.3 November 20, 2023 23:15
@vojtasvoboda
Copy link

vojtasvoboda commented Nov 21, 2023

@wisskid But the range() function is not implemented in v4.3.4 either and works well (i didn't find any range mention in the whole repository) :-) I thought Smarty just call global functions (and also native PHP functions) without any extra definition.

For example when I create a custom global function my_custom_strtoupper(string $name) and call:

{my_custom_strtoupper('Vojta')}

It works.

So in Smarty 5.x.x calling existing functions (and also native PHP functions) will be disabled?

@wisskid
Copy link
Contributor Author

wisskid commented Nov 21, 2023

Yes, that is correct. @vojtasvoboda more specifically: you can still use them, but you'll have to register them first or include them in a custom extension.

@wisskid wisskid added this to the 5.0 milestone Dec 7, 2023
@wisskid wisskid modified the milestones: 5.0, 5.1 Feb 18, 2024
@wisskid wisskid modified the milestones: 5.1, 5.0 Mar 15, 2024
@wisskid wisskid changed the base branch from support/4.3 to support/4 March 15, 2024 15:18
@wisskid wisskid merged commit c7a2713 into support/4 Mar 18, 2024
12 checks passed
@KarelWintersky
Copy link

how to disabled this?

@wisskid
Copy link
Contributor Author

wisskid commented Mar 25, 2024

You cannot and should not, but you can configure your error reporting and/or logging to ignore deprecation notices.

@magrigry
Copy link

magrigry commented Jun 20, 2024

Could you tell us what is the recommended way for accessing constants or class constants ? Same for static method call

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

Successfully merging this pull request may close these issues.

Drop support for using PHP functions as modifiers
5 participants