Skip to content

When a file is loaded from existing PHP code, any readonly keyword in a promoted parameter is ignored #110

@Coffelius

Description

@Coffelius

Version: 4.0.1

Bug Description

The readonly keyword in a promoted parameter is not taken into account by the extractor.

Steps To Reproduce

This piece of code:

$file = PhpFile::fromCode(<<<XX
    <?php
    class Test {
        public function __construct(private readonly string \$foo)
        {
        }
    }
    XX);
$printer = new PsrPrinter();
echo $printer->printFile($file);

Prints:

<?php

class Test
{
    public function __construct(private string $foo)
    {
    }
}

The readonly keyword disappeared.

Expected Behavior

The expected result is:

<?php

class Test
{
    public function __construct(private readonly string $foo)
    {
    }
}

The readonly keyword has been passed thru the extractor as expected.

Possible Solution

I have ready a solution in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions