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

Property with multiple props and property hooks should be a parse error #1050

Open
ondrejmirtes opened this issue Dec 11, 2024 · 4 comments · May be fixed by #1052
Open

Property with multiple props and property hooks should be a parse error #1050

ondrejmirtes opened this issue Dec 11, 2024 · 4 comments · May be fixed by #1052

Comments

@ondrejmirtes
Copy link
Contributor

This piece of code:

class Foo
{
    
    public $foo, $bar { get {} }
    
}

Is rejected by PHP with error message: Parse error: syntax error, unexpected token “{”, expecting “,” or “;” in /in/RndUG on line 6

But PHP-Parser does not report syntax error and represents this with an AST.

Multi-props with property hooks are not supported in PHP. I'm asking about this to find out if this should be a parse error in PHP-Parser, or if this is going to be represented with an AST and PHPStan should come with a custom rule to detect it.

Thanks.

@nikic
Copy link
Owner

nikic commented Dec 11, 2024

I'm fine with having this as a parse error.

@ondrejmirtes
Copy link
Contributor Author

Thanks. Unfortunately I don't know how to implement this one, grammar is still out of my expertise.

@nikic
Copy link
Owner

nikic commented Dec 11, 2024

This one wouldn't be checked directly in the grammar, it needs a manual check like the one here:

/** @param PropertyHook[] $hooks */
protected function checkPropertyHookList(array $hooks, int $hookPos): void {
if (empty($hooks)) {
$this->emitError(new Error(
'Property hook list cannot be empty', $this->getAttributesAt($hookPos)));
}
}

@ondrejmirtes ondrejmirtes linked a pull request Dec 11, 2024 that will close this issue
@ondrejmirtes
Copy link
Contributor Author

Alright, tried it: #1052

Had to modify the grammar anyway 😅

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 a pull request may close this issue.

2 participants