smarty icon indicating copy to clipboard operation
smarty copied to clipboard

instanceof cannot be called on return value of a function Smarty-3.1.39

Open oschonrock opened this issue 4 years ago • 4 comments

this works

{if $object instanceof SomeClass}yes{/if}

This does not (eventhough it used to under php 7.4 and Smarty 3.1.14). Problem occurs with php8.0 and pph7.4

{if get_object() instanceof SomeClass}yes{/if}

workaround is:

{$object = get_object()}
{if $object instanceof SomeClass}yes{/if}

somewhat related to https://github.com/smarty-php/smarty/issues/191

oschonrock avatar Oct 01 '21 16:10 oschonrock

It is bad practice to use application logic in views.

sergant210 avatar Oct 15 '21 05:10 sergant210

How is get_object() instanceof any more "application logic" than $object instanceof?

The point is: It used to work in smarty 3.1.14 and it does not in 3.1.39. So it is a regression, unless it has been intentionally removed?

oschonrock avatar Oct 15 '21 06:10 oschonrock

instanceof is application logic. Do this check in the controller.

sergant210 avatar Oct 15 '21 08:10 sergant210

It's a null check. This is pure opinion/style.

We have been using smarty for 18years.

instanceof has worked since v3. It works in 3.1.14 and in 3.1.39

but f() instanceof works only in the former.

Is this an intentional removal of a feature in a minor version change, or is this a regression which you are justifying with an opinion about style?

oschonrock avatar Oct 15 '21 08:10 oschonrock