Re: Consensus Gathering: is_initialized

From: Date: Thu, 27 May 2021 16:13:11 +0000
Subject: Re: Consensus Gathering: is_initialized
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-114648@lists.php.net to get a copy of this message
On 27.05.21 16:43, Rowan Tommins wrote:
isset in this case is abused to check for uninitialized, hiding the actual intent
On the contrary, the uninitialized state is what is being abused. If you want to make the intent clear, use a clear flag of "needs lazy-loading", or whatever you're actually using this magic "not null but not really anything else either" state for.
How is "uninitialized" magic? It is a state of a class property in PHP that is currently being exposed via reflection, and I have seen quite a few places where it occurs - for example with setter injection in frameworks, as an alternative to setting a property in the constructor. I also prefer properties with default values or values defined in the constructor, yet making it easy to check on something that already exists in the language only seems sensible to me - and I don't see a way of getting rid of that state anytime soon.

« previous php.internals (#114648) next »