Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Returned values by functions can only be assigned to variant variables

Can someone explain me why this is happening and what to do with it?

    public function test(string! text)
    {
        int index;
        char ch;
        array chCode = [];

        for ch in text {
            let index = ord(ch);
            let chCode[index] = ch;
        }

        return chCode;
    }

Zephir\CompilerException: Returned values by functions can only be assigned to variant variables in

/home/klay/projects/zephir/test/foo/bar.zep on line 312

let index = ord(ch);

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



805
Accepted
answer
edited Jan '15

Replace

 int index;

with

var index;

and you are in business.

let index = (int) ord(ch);