Skip to content

PHPStan reports an error when unsetting a plain property that implements an abstract get hook #15792

Open
phpstan/phpstan-src
#7154

Description

@binaryfire

Bug report

BaseRecord declares an abstract get hook for $name. Record implements it with a plain property. PHPStan 2.3.7 reports Cannot unset hooked Record::$name property. on line 14, even though Record::$name has no hooks.

Code snippet that reproduces the problem

<?php declare(strict_types=1);

abstract class BaseRecord
{
    abstract public string $name { get; }
}

final class Record extends BaseRecord
{
    public string $name = 'demo';
}

$record = new Record();
unset($record->name);

PHPStan playground (select PHP 8.4)

Expected output

No errors. PHP 8.4.27 runs this example successfully.

I also reported the underlying reflection bug in Roave/BetterReflection#1599.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions