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

using const in a class in a non-consecutive order throws a ParseException #26

Open
sergeyklay opened this issue Oct 10, 2017 · 0 comments

Comments

@sergeyklay
Copy link
Member

From @chilimatic on September 29, 2017 9:29

the parser throws an syntax error if const are not declared in an consecutive block

namespace Bugreport;

class ConstOrder {
    const MY_FIRST_CONST = "test";

    private $oneProperty = 1;

    const MY_SECOND_CONST = "test2";
}

zephir\Parser\ParseException: Syntax error in /home/j/development/repos/bugreport-zephir/bugreport/bugreport/constorder.zep on line 7

this works.

namespace Bugreport;
class ConstOrder {
    const MY_FIRST_CONST = "test";
    const MY_SECOND_CONST = "test2";

    private $oneProperty = 1;
}

I know splitting consts with other parameters is ugly and I just ran into this error by accident.
At least if we're following the classic patterns and structures.

namespace Bugreport;

class ExampleAction {

    const MY_ACTION_NAME = "MY_ACTION_NAME";
    public static createMyAction(array payload): void {
        return [
            "type": self::MY_ACTION_NAME,
            "payload": payload
        ]
    }

    const MY_OTHER_ACTION_NAME = "MY_OTHER_ACTION_NAME";
    public static createMyOtherAction(array payload): void {
       return [
           "type": self::MY_OTHER_ACTION_NAME,
           "payload": payload
       ]
    }
}

(this is an 1:1 adaption of the declarative CQRS, Redux (js) implementation of an action)

this for example is another way to structure code more contextualized.
I know we could just extract this to a flyweight pattern but that's not the point.

The point is, it's an undefined behaviour and just getting "syntax error" is not enough feedback, since it's syntactically correct at least you don't write any specifics in your documentation https://docs.zephir-lang.com/en/latest/oop.html

Copied from original issue: zephir-lang/zephir#1582

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

No branches or pull requests

1 participant