Skip to content

Class attribute gets duplicated on another class property #2436

Closed
glayzzle/php-parser
#1225

Description

@hackel

The Deprecated attribute is being copied from the TYPES constant to the neighbouring $attributes property for some reason. I have to remove it manually whenever I format this file.

@prettier/plugin-php v0.22.4
Playground link

Input:

<?php

namespace App\Models;

class QuoteSearch extends Model
{
    #[Deprecated(message: 'use \App\Enums\MoveType')]
    public const TYPES = [
        'IMPORT' => 'import',
        'EXPORT' => 'export',
    ];

    protected $attributes = [
        'search_job_completed' => false,
    ];
}

Output:

<?php

namespace App\Models;

class QuoteSearch extends Model
{
    #[Deprecated(message: "use \App\Enums\MoveType")]
    public const TYPES = [
        "IMPORT" => "import",
        "EXPORT" => "export",
    ];

    #[Deprecated(message: "use \App\Enums\MoveType")]
    protected $attributes = [
        "search_job_completed" => false,
    ];
}

Activity

  1. czosel commented on Jul 11, 2025

    @czosel
    Collaborator

    Thanks for the bug report @hackel!

  2. hackel commented on Jul 3, 2026

    @hackel
    ContributorAuthor

    @czosel @jorgsowa Unfortunately glayzzle/php-parser#1225 does not appear to have fixed this issue. I just confirmed it with a new install against the example I gave above, and got the exact same result.

    @prettier/plugin-php@0.25.0
    prettier@3.9.4
    linguist-languages@8.2.0
    php-parser@3.7.0

  3. maoxor commented on Oct 29, 2026

    @maoxor

    Still happening with 0.26.0 (php-parser 3.7.0): the parser resets the attribute list after methods and properties but not after class constants, so the next member inherits the constant's attributes. glayzzle/php-parser#1309 fixes it, with a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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