Re: [RFC] __exists(), a magic method for distinguishing "missing" from "set to null"
| From: | Larry Garfield | Date: | Sat, 02 May 2026 15:44:56 +0000 |
| Subject: | Re: [RFC] __exists(), a magic method for distinguishing "missing" from "set to null" | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130742@lists.php.net to get a copy of this message | ||
On Fri, May 1, 2026, at 4:37 AM, Nicolas Grekas wrote:
> Dear internals,
>
> It's my pleasure to submit this new RFC to yours.
> Please have a look and let me know:
> https://wiki.php.net/rfc/exists-magic-method
>
> TL;DR: I'm proposing a new opt-in magic method:
>
> public function __exists(string $name): bool;
>
> It'd let userland tell "set to null" apart from "missing" on objects,
> it'd restore
> isset() <=> ?? equivalence on magic properties, and it'd fixe GH-12695
> as a
> corollary. It's forward-compatible as a regular method on PHP <= 8.5
> (probeable
> via method_exists()), and would be magic on 8.6+.
>
> Cheers,
> Nicolas
Thanks for the very detailed RFC!
> If it returns false, the fetch produces “uninitialized” (treated as null by ??, so y is
> evaluated). __get() is not called.
What is y? Looks like a reference to a previous iteration of the text.
The Sequencing section also doesn't describe the behavior when __exists() isn't defined.
Does it just skip to step 4? (Please specify in the text.)
Is the intent to eventually deprecate __isset()? The RFC it doesn't now, but do you feel that
is the eventual end-game, in PHP 10 or whatever?
The big one: Should any parallel changes or additions be made to property hooks? An exists()
operation in addition to get/set, for instance? (I'm not sure at the moment, but it should be
thought through and discussed, and if not, documented in the RFC.)
--Larry Garfield