Skip to content

Support PHP 8.4 Asymmetric Property visibility #2926

@TunaMaestro

Description

@TunaMaestro

phpactor version: master@a0bd607423e09f7c6bea63e2b97127dd71f28e9b

Asymmetric properties don't parse and also cause issues with the parsing of other parts of the file like methods.

The below is a screenshot of the amended excerpt from the php manual. https://www.php.net/manual/en/language.oop5.visibility.php#language.oop5.visibility-members-aviz

<?php

class Book
{
    public function __construct(
        public private(set) string $title,
        public protected(set) string $author,
        protected private(set) int $pubYear,
    ) {}

    public function methodThatNowWontParse(): void
    {}
}

class SpecialBook extends Book
{
    public function update(string $author, int $year): void
    {
        $this->author = $author; // OK
        $this->pubYear = $year; // Fatal Error
    }
}


$b = new Book('How to PHP', 'Peter H. Peterson', 2024);

$b->methodThatNowWontParse();

echo $b->title; // Works
echo $b->author; // Works
echo $b->pubYear; // Fatal Error

$b->title = 'How not to PHP'; // Fatal Error
$b->author = 'Pedro H. Peterson'; // Fatal Error
$b->pubYear = 2023; // Fatal Error
Image

The feature of asymmetric rules is less important than the bug of the syntax affecting other parsing.

Thanks

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