smarty-php / smarty

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

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

Closed wisskid closed 5 months ago

wisskid commented 1 year ago

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

Fixes #813

vojtasvoboda commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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

vojtasvoboda commented 9 months ago

@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 commented 9 months ago

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.

KarelWintersky commented 5 months ago

how to disabled this?

wisskid commented 5 months ago

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

magrigry commented 2 months ago

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