Skip to content

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

Open
@sergeyklay

Description

@sergeyklay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions