prettier / prettier/plugin-php
Class Name From Class Variable Throws Exception
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
There seems to be a PHP Prettier parse exception when ::class is called on a class property. This is a contrived example, but the following is a minimal reproducible example that throws an exception when checked:
class Test
{
public $exception;
public function test()
{
$this->exception = new \Exception("test");
return $this->exception::class; // Throws "SyntaxError: Parse Error : syntax error, unexpected 'class' (T_CLASS)"
}
}
Happens on the PHP Prettier playground and my local with:
- Node
18.20.5 - Prettier
3.4.2 - PHP Prettier
0.22.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the exception with the minimal class-property example in the PHP Prettier playground or the listed local versions. Trace how the parser handles $this->exception::class, then add coverage for this case. Done means the example is accepted and formatted without the reported T_CLASS parse error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100