Skip to content

Unsetting array item triggers unset.possiblyHookedProperty #12695

@mmarton

Description

@mmarton

Bug report

Hi!

the most recent version added some new rules about hooked property unset. I'm trying to find out, that this is expected behavior or a bug.

I can't create a reproducer as I'm using 3rd party code, but I have something like this:


<?php declare(strict_types = 1);

namespace App\Monolog\Handler;

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;

class MynHandler extends AbstractProcessingHandler
{
    protected function write(LogRecord $record): void
    {
		// ...
        unset($record->formatted['context']['target']);
        // ...
    }
}

This shows the error:

Cannot unset property Monolog\LogRecord::$formatted because it might have hooks in a subclass.

But I'm not unsetting the whole property only part of it.

Code snippet that reproduces the problem

No response

Expected output

probably no error

Did PHPStan help you today? Did it make you happy in any way?

yes, as allway :)

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