Open
Description
Description
i'm able to trigger an infinite recursion by using isset() on a private(set) property that has a get hook:
<?php
// https://github.com/php/php-src/issues/18318
$foo = new CatchMeIfYouCan();
var_dump($foo->bar);
final class CatchMeIfYouCan
{
private(set) int $bar
{
get => $this->bar ??= $this->fooBar();
}
public function fooBar(): int
{
isset($this->bar);
}
}
this came unexpected to me as it is normally possible to make use of isset() or ??= within a class safely.
expected is to fail as fooBar() does not return an integer.
and it seems to me that the use of ??= on the member is only possible within the hook, but not within a different place in the class's protocol.
example:
...
public function fooBar(): int
{
return $this->bar ??= 1;
}
}
PHP Version
PHP 8.4.5 (cli) & php-src/sapi/cli/php
Operating System
No response