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

instanceof fails if checked against a variable #92

Closed
schinkel-zz opened this issue Sep 18, 2015 · 4 comments
Closed

instanceof fails if checked against a variable #92

schinkel-zz opened this issue Sep 18, 2015 · 4 comments

Comments

@schinkel-zz
Copy link

Consider the following code:

{$interface = 'a_random_interface'}
{$object = 'a string'}
{if $object instanceof $interface}
    <p>All good</p>
{else}
    <p>Something's wrong</p>
{/if}

This worked like a charm up until Smarty 3.1.23, but fails in Smarty 3.1.24 and upwards with the following error message:

PHP Fatal error:  Uncaught  --> Smarty Compiler: Syntax error in template "/var/www/examples/templates/correct.tpl"  on line 3 "{if $object instanceof $interface}"  - Unexpected "$interface", expected one of: "id, name" , NAMESPACE <-- 
  thrown in /var/www/examples/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 3

I am using the following code to render this template:

$smarty = new \Smarty();
$smarty
    ->setCompileDir(sys_get_temp_dir())
    ->setCacheDir(sys_get_temp_dir())
    ->setPluginsDir(SMARTY_PLUGINS_DIR)
    ->disableSecurity();
$smarty->display(__DIR__ . '/templates/correct.tpl');

The following snippet does compile and produces the expected "Something's wrong":

{$interface = 'a_random_interface'}
{$object = $smarty}
{if $object instanceof aaa}
    <p>All good</p>
{else}
    <p>Something's wrong</p>
{/if}
@Henkiebob
Copy link

+1

@uwetews
Copy link
Contributor

uwetews commented Sep 18, 2015

I can confirm this bug. The fix will go into the master branch and version 3.1.28 in a few days.

Possible fix:

in lexer/smarty_internal_templateparser.y

expr(res)        ::= variable(v1) INSTANCEOF(i) ns1(v2). {
      res = v1.i.v2;
}

expr(res)        ::= variable(v1) INSTANCEOF(i) variable(v2). {
      res = v1.i.v2;
}

add the second expression.

Get with composer "smarty/smarty-lexer": "~3.1@dev"
Run Create_Template_Parser.php

Because of other changes under work I can't commit it directly immediately

.

@uwetews
Copy link
Contributor

uwetews commented Dec 4, 2015

The fix is now available in the master branch and will be included in the upcoming 3.1.28

@uwetews uwetews closed this as completed Dec 4, 2015
@schinkel-zz
Copy link
Author

Cool, thanks!

think-mcunanan pushed a commit to think-mcunanan/smarty that referenced this issue Mar 22, 2023
…-same-starttime-menus-ignore-rowno

#5479: 開始時刻が同一の場合、メニューの並び順(行番号)が無視されてしまう
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

No branches or pull requests

3 participants