zephir
zephir copied to clipboard
For loop, key on traversing string
It's not possible to move key during the loop on the string variable;
public function filter(string str)
{
string output = "";
char c;
int i;
for i, c in str {
if c == '\n' {
let i++;
}
let output .= c;
}
}
for (_0 = 0; _0 < Z_STRLEN_P(str); _0++) {
i = _0;
c = ZEPHIR_STRING_OFFSET(str, _0);
is it possible to get access to _0
variable?
You might want to use a 'while' instead of a 'for'
I'm doing that now..
Yes, you can always convert your for loop into equivalent while loop. Check out my tool: https://github.com/jimthunderbird/php-to-c-extension#example-04
I think this is a bug.
It should use i
in the loop:
for (i = 0; i < Z_STRLEN_P(str); i++) {
or replace inside loop:
let i++;
to
_0++;
because now i++
is useless. @ovr @nkt what do you think?