Skip to content

Deadcatch on property assignment #6256

@SamMousa

Description

@SamMousa

Bug report

PHPStan doesn't seem to realize that a property assignment can throw a TypeError.

Code snippet that reproduces the problem

https://phpstan.org/r/e4d99651-8429-4a59-8994-6f1f975d58a0

<?php declare(strict_types = 1);
class A {
    public int $b;
}

$test = new A();
function setProp(string $prop, object $object): void {
	try {
		$object->$prop = "abc";
	} catch (\TypeError $e) {
	}
}

Expected output

No error

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

Yes, see my other stories ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions