alexeyrybak/blitz

{{ IF }} interprets true as false

Closed this issue · 5 comments

When returning true from a function called from Blitz, it doesn't interpret it as true when evaluating it in an if-expression and it takes the else-branch as a result.

Demo code:

<?php
var_dump(php_uname('a'));
var_dump(phpversion());
var_dump((new ReflectionExtension('blitz'))->getVersion());

class View extends Blitz {
    function m() {
        return true;
    }
}

$T = new View();
$T->load("{{ IF m() }}TRUE{{ ELSE }}FALSE{{ END }}");
var_dump($T->parse());

Output:

string(128) "Darwin MBP-Maurus 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64"
string(6) "5.5.25"
string(6) "0.8.18"
string(5) "FALSE"

If this is deemed invalid behaviour (eg function calls are not allowed in if context), throwing a parser exception would really help the developer in question to understand why this is not working.

Confirm, it's repeatable and it's unexpected (either warning/exception that functions are not supported, or work exactly as expected).

Let me have a look

Better error's are spawned in PR #29

This is what will be shown in 0.9.1
Warning: blitz::load(): SYNTAX ERROR: invalid syntax, empty expression between the brackets (noname_loaded_from_zval: line 1, pos 1)