Skip to content

Incorrect behavior of ChangeReadOnlyVariableWithDefaultValueToConstantRector #7650

@DAcodedBEAT

Description

@DAcodedBEAT

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.org/demo/3565a3fa-2ab3-495f-b900-1a9e6ff00990

<?php

final class DemoFile
{
    public function run()
    {
        $foo = 'I like pie';
        
        $bar = <<<EOD
And on this day, it was spoken - "$foo"

EOD;
    }
}

Responsible rules

  • ChangeReadOnlyVariableWithDefaultValueToConstantRector

Expected Behavior

This code would remain unaffected, as the current suggestion And on this day, it was spoken - "{self::FOO}" in invalid.

Reasoning:
The variable used in the string interpolation cannot be converted into a constant because you cannot use values of class constants or static class variables in string interpolation, as per https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing .

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