Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

Issues with the for loop and the unset statement #13

Closed
inspektorsowa opened this issue Jul 15, 2015 · 5 comments
Closed

Issues with the for loop and the unset statement #13

inspektorsowa opened this issue Jul 15, 2015 · 5 comments

Comments

@inspektorsowa
Copy link

Hi there,
it seems that the library doesn't manage with the "for" loop and the "unset" statement.

This is my PHP code:

<?php
namespace Brainusers;
class ZephirTest {
    static public function hello() {
        $obj = array();
        for ($i=0; $i<1000; $i++) {
            $obj[] = new ZephirTest();
        }
        unset($obj);
    }
}

Output is:

namespace Brainusers;

class ZephirTest
{
    public static function hello() -> void
    {
        var obj, i;


        let obj =  [];
        for let i = 0; i < 1000; let i++ {
            let obj[] = new ZephirTest();
        }
        unset(obj);

    }

}

Trying to build:

$ zephir build
Zephir\ParseException: Syntax error in /php2zephir/brainusers/brainusers/zephirtest.zep on line 11

            for let i = 0; i < 1000; let i++ {
    --------------^

After changed to for i in range(0,1000) there is a problem with unset:

$ zephir build
Zephir\CompilerException: Cannot use expression type: variable in "unset" in /php2zephir/brainusers/brainusers/zephirtest.zep on line 14

            unset(obj);
    -----------------^
fezfez added a commit that referenced this issue Jul 16, 2015
@fezfez
Copy link
Owner

fezfez commented Jul 16, 2015

Hi !

I fix the for loop.

For the unset statement, the translation is correct maybe open a ticket at https://github.com/phalcon/zephir/issues/

Thanks for the report !

@inspektorsowa
Copy link
Author

Thank you for a such quick reply.

The unset() in PHP is more like a language expression than a function.

unset($a);

However in Zephir to unset a variable you have to use it without brackets (like an echo):

unset a;

So maybe you can change the conversion unset($a) to unset a?

fezfez added a commit that referenced this issue Jul 16, 2015
@fezfez
Copy link
Owner

fezfez commented Jul 16, 2015

I cant test Zephir compilation right now, so i trust you and i change the unset translation.
Can you test with master ?

Thanks !

@inspektorsowa
Copy link
Author

Now the unset works only for the array elements, but not for variables. I will notify the Zephir devs. Thanks.

@fezfez
Copy link
Owner

fezfez commented Jul 16, 2015

Thanks !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants