Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elseif support #536

Merged
merged 6 commits into from
Sep 14, 2014
Merged

Elseif support #536

merged 6 commits into from
Sep 14, 2014

Conversation

nkt
Copy link
Contributor

@nkt nkt commented Sep 13, 2014

No description provided.

@nkt nkt changed the title Elseif support [Not ready] Elseif support Sep 13, 2014
@ovr
Copy link
Contributor

ovr commented Sep 14, 2014

elseif = else if?

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@ovr I thought about it, I don't like it.
@phalcon, @niden, @dreamsxin, @mruz what do you prefer, elseif, else if or both?

@mruz
Copy link
Contributor

mruz commented Sep 14, 2014

I prefer elseif thanks for this support.

@phalcon
Copy link

phalcon commented Sep 14, 2014

Current implementation does not work well with this structure:

namespace Test;

class X
{
        public static function x(a)
        {
                if a == 1 {
                        echo "x";
                } elseif a == 2 {
                        echo "y";
                } elseif a == 3 {
                        echo "z";
                } else {
                        echo "?";
                }
        }
}

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@phalcon why do you think that? There is no a defined.
Zephir compile this code into:

PHP_METHOD(Test_Statements, echoElseifTest) {

    zval *a_param = NULL;
    int a;

    zephir_fetch_params(0, 1, 0, &a_param);

    a = zephir_get_intval(a_param);


    if (a == 1) {
        php_printf("x");
    } else if (a == 2) {
        php_printf("y");
    } else if (a == 3) {
        php_printf("z");
    } else {
        php_printf("?");
    }

}

@phalcon
Copy link

phalcon commented Sep 14, 2014

Yeah, I know, it's not about compilation, it's about parsing:

$ bin/zephir-parser a.zep 
{ "type": "error", "message": "Syntax error", "file": "a.zep", "line": 4, "char": 7 }

@ovr
Copy link
Contributor

ovr commented Sep 14, 2014

Compile from

Zephir elseif
to
C code else if

Funny

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@phalcon that is not problem of this PR, that is problem related to UPPERCASED_NAMES defines as constants, so classes and method names can not be in uppercase, like X 😄

@phalcon
Copy link

phalcon commented Sep 14, 2014

😢 you're right lol

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@phalcon look at #141

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@ovr C and PHP also lets write code like:

if (a < b) foo();
else bar();

And I hate this style, it helps to create stupid mistakes. else if is one possible use-case for C that I allow for me.

@phalcon
Copy link

phalcon commented Sep 14, 2014

I'm ok with elseif

@nkt
Copy link
Contributor Author

nkt commented Sep 14, 2014

@phalcon are you going to merge this?

phalcon pushed a commit that referenced this pull request Sep 14, 2014
@phalcon phalcon merged commit db0c6e7 into zephir-lang:master Sep 14, 2014
@nkt nkt deleted the feature/else-if branch September 14, 2014 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants