Re: [DISCUSSION] Checking uninitialized class properties

From: Date: Sat, 18 May 2024 17:41:58 +0000
Subject: Re: [DISCUSSION] Checking uninitialized class properties
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-123354@lists.php.net to get a copy of this message
On 18 May 2024 17:13:49 BST, Larry Garfield <larry@garfieldtech.com> wrote: >However, that breaks down with readonly properties, which are not allowed to have a sentinel. >Uninitialized is their sentinel, for better or worse. Sorry, I don't understand this statement at all. A readonly property can be set to PatchState::KeepCurrentValue just like any other. If the intention is that that state will be overwritten with an actual value later, then it's not a readonly property. I guess you have some different scenario in mind? > And as I noted earlier in the thread, when writing a serializer or other dynamic systems (an > ORM probably would have the same issue), you really need to be able to differentiate between null > and uninitialized. Even if you think the uninitialized value is a sign of an error, it's > coming from code you don't control so you have to be able to handle it somehow. If a property is uninitialized, the object is in an invalid state, and attempting to read that property gives an error. That's by design, and as it should be. Are you saying that you want to be able to detect the error before it happens? Why? Rowan Tommins [IMSoP]

« previous php.internals (#123354) next »