empty function problem in zephir?

there's another question is as follows that about 'empty' function in zephir. The code is:

public function testEmpty()->void
{
    var someVar;
    let someVar = 0;
    echo typeof(someVar) . "\n";
    if empty someVar {
        echo "is empty!";
    }
}

When I use 'zephir build' command, it appears this:

[[email protected] utils]# zephir build
Zephir\CompilerException: Only dynamic/string variables can be used in 'empty' operators in /root/utils/utils/filter.zep on line 23

    if empty someVar {

-------------------------^

Then, I modify code as follows:

public function testEmpty()->void
{
    // var someVar;
    // let someVar = 0;
    // echo typeof(someVar) . "\n";
    // if empty someVar {
    //     echo "is empty!";
    // }


    var someVar;
    let someVar = "";
    echo "\n" . typeof(someVar) . "\n";
    let someVar = 0;
    echo typeof(someVar) . "\n";
    if empty someVar {
        echo "is empty!";
    }
}

buid again:

[[email protected] utils]# zephir build Compiling... Installing... Extension installed! Don't forget to restart your web server

This time is OK. so the test result as follows:

[[email protected] utils]# php example/test.php 
string
integer
is empty!

So, my question is why first condition code build failure? In the second condition just assign string to varablie beofore assign 0 to it, Thanks.



64.2k

create your own method instead, zephir is not php

something like this should work

/**
* returns if value is empty or 0
*
* @param $value
*
* @return bool
*/
public static function isEmpty(value) {

    return (value === null) || (value === '') || (value === 0) || (is_array(value) && count(value) === 0);
}


580

So I think 'empty' function may be have a problem, because I in the first condition, it appears 'Zephir\CompilerException: Only dynamic/string variables can be used in 'empty' operators',please notice that 'Only dynamic/string variables can be used',so I defined a varaible by 'var' that means this's a dynamic variable.So Why not can pass complilation? If not, I think the hint is not exactly correct or may be 'empty' function have a problem for this conditon?

create your own method instead, zephir is not php

something like this should work

``` /** * returns if value is empty or 0 * * @param $value * * @return bool */ public static function isEmpty(value) {

return (value === null) || (value === '') || (value === 0) || (is_array(value) && count(value) === 0); }

```



64.2k

no idea really, but C language has its own "things", stuff do no magically happen like in php. Everything is 100% strict there



580

Thanks, but i can't understand why the second condition code can pass build, if the first can't, I think the second shouldn't pass compilation.So I doubt here.

no idea really, but C language has its own "things", stuff do no magically happen like in php. Everything is 100% strict there