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 #1582

Closed
chilimatic opened this issue Sep 29, 2017 · 1 comment
Closed
Assignees

Comments

@chilimatic
Copy link

chilimatic commented Sep 29, 2017

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

@chilimatic chilimatic changed the title mixing protected / const / protected leads to compile error using const in a class in a non-consecutive order throws a ParseException Sep 29, 2017
@sergeyklay sergeyklay self-assigned this Oct 2, 2017
@sergeyklay
Copy link
Contributor

This issue was moved to zephir-lang/php-zephir-parser#26

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

No branches or pull requests

2 participants