smarty-php / smarty-php/smarty

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

Open
#677 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Smarty template expressions under PHP 8.0 and PHP 7.4, comparing the direct variable case with the function-return case and the documented workaround. Done means a function return can be used with instanceof in the conditional, while the existing variable form continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.