Skip to content

Incorrect behavior of ClassPropertyAssignToConstructorPromotionRector #8568

@micaherne

Description

@micaherne

Bug Report

It looks like the refactoring of class properties to promoted constructor properties doesn't work as expected in this case (presumably because it's using the var keyword?)

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/3b9b99c4-80ee-46d1-b408-85833b215ce3

<?php

class test {

    var $id;

    public function __construct($id) {
        $this->id = $id;
    }
}

Responsible rules

  • ClassPropertyAssignToConstructorPromotionRector

Expected Behavior

Rector should leave this alone. If combined with VarToPublicPropertyRector (as in the up to PHP 8.2 set) it should change the var to a public property and then to a promoted constructor parameter.

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