prettier / prettier/plugin-php

Class Name From Class Variable Throws Exception

Open
#2,410 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.