Re: [RFC] __exists(), a magic method for distinguishing "missing" from "set to null"
| From: | Nicolas Grekas | Date: | Sat, 30 May 2026 12:24:27 +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-131069@lists.php.net to get a copy of this message | ||
Dear internals,
Le ven. 1 mai 2026 à 11:37, Nicolas Grekas <nicolas.grekas+php@gmail.com> a
écrit :
> 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+.
>
Following the feedback received so far, you might have seen that I've split
the materialized property check into a separate PR/thread, see
https://externals.io/message/131068
I therefore updated the text of the RFC, now at v0.2, to account for that
materialization issue being addressed separately.
I also updated the wording to mention the points that have been discussed
and simplify the wording a bit (less repetitions, less C-side stuff).
I didn't update the implementation yet, but technically the TL;DR of this
new iteration is that it brings nothing new: it's only a refacto of the
presentation.
This message starts a new discussion period.
Cheers,
Nicolas