Skip to content

Conversation

cseufert
Copy link
Collaborator

@cseufert cseufert commented Mar 10, 2021

Basic impementation of promoted properties.

Added new AST node promotedparameter which is based on parameter with added promote property which can be public, private, or protected.

Is this the correct way to do this?

@coveralls
Copy link

coveralls commented Mar 10, 2021

Coverage Status

Coverage increased (+0.02%) to 96.084% when pulling f863389 on moddengine:php8-promoted-properties into 82970fd on glayzzle:php8.

@cseufert
Copy link
Collaborator Author

This should close #655

@cseufert cseufert changed the title PHP 8 Promoted Properties feat(php8): promoted properties Mar 22, 2021
@cseufert cseufert mentioned this pull request Mar 22, 2021
1 task
@cseufert cseufert changed the base branch from master to php8 March 24, 2021 10:34
@cseufert
Copy link
Collaborator Author

@czosel I think this approach should be changed in favour of how https://github.com/nikic/PHP-Parser/ handles it, and add a Param.flags that holds a int flag for visibility (public/private/protected) rather than a new ast node type. Ill add another PR for that when I get a chance

@czosel
Copy link
Collaborator

czosel commented Mar 26, 2021

For reference: PHP-Parser parses

class __proto__ {
  public function constructor(public int $id, private $name, protected ServerRequestInterface $req) {}
}

as

array(                                                                                                                                                                                                                                                 
    0: Stmt_Class(                                                                                                                                                                                                                                     
        attrGroups: array(                                                                                                                                                                                                                             
        )                                                                                                                                                                                                                                              
        flags: 0                                                                                                                                                                                                                                       
        name: Identifier(                                                                                                                                                                                                                              
            name: __proto__                                                                                                                                                                                                                            
        )                                                                                                                                                                                                                                              
        extends: null                                                                                                                                                                                                                                  
        implements: array(                                                                                                                                                                                                                             
        )                                                                                                                                                                                                                                              
        stmts: array(                                                                                                                                                                                                                                  
            0: Stmt_ClassMethod(
                attrGroups: array(
                )
                flags: MODIFIER_PUBLIC (1)
                byRef: false
                name: Identifier(
                    name: constructor
                )
                params: array(
                    0: Param(
                        attrGroups: array(
                        )
                        flags: MODIFIER_PUBLIC (1)
                        type: Identifier(
                            name: int
                        )
                        byRef: false
                        variadic: false
                        var: Expr_Variable(
                            name: id
                        )
                        default: null
                    )
                    1: Param(
                        attrGroups: array(
                        )
                        flags: MODIFIER_PRIVATE (4)
                        type: null
                        byRef: false
                        variadic: false
                        var: Expr_Variable(
                            name: name
                        )
                        default: null
                    )
                    2: Param(
                        attrGroups: array(
                        )
                        flags: MODIFIER_PROTECTED (2)
                        type: Name(
                            parts: array(
                                0: ServerRequestInterface
                            )
                        )
                        byRef: false
                        variadic: false
                        var: Expr_Variable(
                            name: req
                        )
                        default: null
                    )
                )
                returnType: null
                stmts: array(
                )
            )
        )

I agree, a visibility flag is the best way to represent this 👍

@cseufert
Copy link
Collaborator Author

Use the implmentaton in #697

@cseufert cseufert closed this Mar 29, 2021
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.

3 participants