var or string ..?

string foo = substr( "foo", 0, 1 );
string bar = strval( "bar" );

It throws Returned values by functions can only be assigned to variant variables ...

I am confused about that ... Isn't substr a function ..?

why can't I assign a absolute string to a string variable ..?

var foo, bar;

let foo = substr( "foo", 0, 1 );
let bar = strval( "bar" );

var_dump(typeof foo);
var_dump(typeof bar);
edited Apr '16

Thank you for the reply ... is there any difference between var and let in this case ..?

var foo, bar;

let foo = substr( "foo", 0, 1 );

let bar = strval( "bar" );

var_dump(typeof foo);

var_dump(typeof bar);

Variables are by default immutable, this means that Zephir expects that most variables stay unchanged. Variables that maintain their initial value can be optimized down by the compiler to static constants.

When the variable value needs to be changed, the keyword let must be used.

Well ... my fault ... I guess I have not made myself clear ...

I mean ... what the difference between ...

string baz;
let baz = strval( "baz" );

... and ...

var baz;
let baz = strval( "baz" );

..? and why the first one didn't work ..?

Variables are by default immutable, this means that Zephir expects that most variables stay unchanged. Variables that maintain their initial value can be optimized down by the compiler to static constants.

When the variable value needs to be changed, the keyword let must be used.

edited Apr '16

Because returned values by any functions can only be assigned to var, not string, array, int, double, etc :) This is language design

So let us back to the very top of this topic ...

string qux = substr( "qux", 0, 1 );

this works as expect without any error ... Isn't substr a function ..?

Because returned values by any functions can only be assigned to var, not string, array, int, double, etc :) This is language design

Yes, substr is function. This is why returned value can't be assigned to qux - qux declared as string instead var.

IT CAN BE ... this code WORKS ... no error ... and I am wondering why ...

Yes, substr is function. This is why returned value can't be assigned to qux - qux declared as string instead var.

edited Apr '16

This is wierd. But anyway you should use var declaration

edited Apr '16

Not just substr actually ... I found several functions can using string defination and others can not ...

I guess zephir should have something like "language construct" but behaves like function ... However I can not find the document about this ...

Anyway ... why var decalration is better than string ... in my opinion I should always use most exact variable declaration ..?

This is wierd. But anyway you should use var declaration

Is this possible reason for that, from php substr documentation: *Returns the extracted part of string; or FALSE on failure, or an empty string. *

Maybe this works in PHP 7 since: *If string is equal to start characters long, an empty string will be returned. Prior to this version, FALSE was returned in this case. *