Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Hossein Baghayi
Out of curiosity, Couldn't PHP raise an error when there is an uninitialized state left unhandled after calling the constructor? It might make the developer think of either providing a default value or initializing it in the constructor. Hence no uninitialized state.

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Larry Garfield
On Thu, May 27, 2021, at 8:23 AM, Rowan Tommins wrote: > The combination of union types and enums actually gives a much more > expressive way of representing "valid value or explicit null or special > default". To use the ORM lazy-loading example: > > > enum ORMState { >     case Unloaded; >

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Rowan Tommins
On 27/05/2021 17:13, Andreas Leathley wrote: How is "uninitialized" magic? It is a state of a class property in PHP that is currently being exposed via reflection Apologies if my last message was a bit too hastily written, and may have come across as rude. What I meant by it being "magic"

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Mike Schinkel
> On May 27, 2021, at 12:05 PM, Rowan Tommins wrote: > > On 27/05/2021 16:33, Mike Schinkel wrote: >> Since the argument against is_initialized() seems to almost universally be >> that we should not write code that lets type properties be uninitialized >> past the constructor then it would f

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Guilliam Xavier
On Thu, May 27, 2021 at 3:55 PM Andreas Leathley wrote: > Also, is_initialized cannot be done in > userland, as passing an unitialized property to a function already leads > to an error > The feature request was indeed `is_initialized($foo->bar)` (language construct, akin to isset); but the PR

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Andreas Leathley
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 actual

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Rowan Tommins
On 27/05/2021 16:33, Mike Schinkel wrote: Since the argument against is_initialized() seems to almost universally be that we should not write code that lets type properties be uninitialized past the constructor then it would follow that PHP is in the wrong to even allow uninitialized state pas

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Mike Schinkel
> On May 27, 2021, at 10:43 AM, Rowan Tommins wrote: > > On 27/05/2021 14:55, Andreas Leathley wrote: >> >> When using isset on a non-nullable property a >> static analyzer would rightfully complain that the property is not >> nullable > > > Precisely, so don't mark a property as non-nullable

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Joe Watkins
Thanks for all the input everyone, very successful consensus gathering exercise. Since the response was pretty overwhelmingly negative, I think we can just stop here. I've closed the PR and wrapped up the FR. Anyone is of course free to pursue the RFC that would be required, however ill advised.

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Rowan Tommins
On 27/05/2021 14:55, Andreas Leathley wrote: When using isset on a non-nullable property a static analyzer would rightfully complain that the property is not nullable Precisely, so don't mark a property as non-nullable and then leave it unset. isset in this case is abused to check for unin

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Andreas Leathley
On 26.05.21 12:13, Joe Watkins wrote: Not absolutely convinced that it's a good idea, I asked Nikita to review, and he's unconvinced also and suggested a discussion should be started. You can read both of our thoughts about it on the PR. What I'm looking for now, is reasons that we are wrong -

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Rowan Tommins
On 27/05/2021 13:07, Pierre wrote: So, if it's going to be used and abused in those magic APIs we all use daily without thinking about it (let's say, hydrators or serializers, dependency injection containers and all that stuff, and you do maintain some if I recall) and unlock some performance o

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Pierre
Le 27/05/2021 à 14:18, Michał Marcin Brzuchalski a écrit : Please take no offense. I just think it's not that common. While I do work with many integration projects most of the time already could forget about writing my own stuff for this kind of thing where I have learned to rely on community-de

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Michał Marcin Brzuchalski
czw., 27 maj 2021 o 13:29 Pierre napisał(a): > Le 26/05/2021 à 21:24, Michał Marcin Brzuchalski a écrit : > > I don't think nowadays anyone does that without a kind of deserializer > > which > > reads the metadata of desired DTO and like Symfony's Serializer or JMS > > which just deal with such t

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Pierre
Le 27/05/2021 à 13:42, Marco Pivetta a écrit : On Thu, May 27, 2021 at 1:29 PM Pierre wrote: why not having it ? More API, similar-but-not-exactly-like `ReflectionProperty#isInitialized()` Minimalims should really be valued more :D I agree and disagree at the same time. I agree because my

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Marco Pivetta
On Thu, May 27, 2021 at 1:29 PM Pierre wrote: > why not having it ? > More API, similar-but-not-exactly-like `ReflectionProperty#isInitialized()` Minimalims should really be valued more :D Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-27 Thread Pierre
Le 26/05/2021 à 21:24, Michał Marcin Brzuchalski a écrit : I don't think nowadays anyone does that without a kind of deserializer which reads the metadata of desired DTO and like Symfony's Serializer or JMS which just deal with such tasks!? Hello, Just for your information, we do have our own

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread David Gebler
On Wed, May 26, 2021 at 11:14 AM Joe Watkins wrote: > Hi internals, > > In response to: https://bugs.php.net/bug.php?id=78480 > > I implemented: https://github.com/php/php-src/pull/7029 > > Not absolutely convinced that it's a good idea, I asked Nikita to review, > and he's unconvinced also and s

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Michał Marcin Brzuchalski
śr., 26 maj 2021 o 18:20 Guilliam Xavier napisał(a): > On Wed, May 26, 2021 at 4:09 PM Larry Garfield > wrote: > > > On Wed, May 26, 2021, at 8:24 AM, Rowan Tommins wrote: > > > On 26/05/2021 11:13, Joe Watkins wrote: > > > > Hi internals, > > > > > > > > In response to: https://bugs.php.net/bug

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Rowan Tommins
On 26/05/2021 17:20, Guilliam Xavier wrote: I think you said the word: serialization. And especially*deserialization*, e.g. from a JSON payload into a typed DTO*without* calling the constructor (then the DTO is passed through validation, which must handle uninitialized typed properties "graceful

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Guilliam Xavier
On Wed, May 26, 2021 at 4:09 PM Larry Garfield wrote: > On Wed, May 26, 2021, at 8:24 AM, Rowan Tommins wrote: > > On 26/05/2021 11:13, Joe Watkins wrote: > > > Hi internals, > > > > > > In response to: https://bugs.php.net/bug.php?id=78480 > > > > > > I implemented: https://github.com/php/php-sr

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Larry Garfield
On Wed, May 26, 2021, at 8:24 AM, Rowan Tommins wrote: > On 26/05/2021 11:13, Joe Watkins wrote: > > Hi internals, > > > > In response to: https://bugs.php.net/bug.php?id=78480 > > > > I implemented: https://github.com/php/php-src/pull/7029 > > > My general feeling remains that the "uninitialized

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Rowan Tommins
On 26/05/2021 11:13, Joe Watkins wrote: Hi internals, In response to: https://bugs.php.net/bug.php?id=78480 I implemented: https://github.com/php/php-src/pull/7029 My general feeling remains that the "uninitialized" state is an awkward hack that we should be working to eliminate with better

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Joe Watkins
Thanks Michal for input ... > Ack, but real-world impact seems irrelevant? I've worked on stuff that heavily relies on checking initialized state, and most of it is mostly unaffected. "meaningful benchmark" means "here's a use-case that really needs `is_initialized()`, and absolutely cannot run in

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Michał Marcin Brzuchalski
śr., 26 maj 2021 o 12:14 Joe Watkins napisał(a): > Hi internals, > > In response to: https://bugs.php.net/bug.php?id=78480 > > I implemented: https://github.com/php/php-src/pull/7029 > > Not absolutely convinced that it's a good idea, I asked Nikita to review, > and he's unconvinced also and sugg

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Marco Pivetta
Hey Joe, On Wed, May 26, 2021 at 12:56 PM Joe Watkins wrote: > Hi Marco, > > What do you mean by "meaningful benchmarks" ? > > There's no question that is_initialized will be faster than the reflector > version, even with reflection caching. > Ack, but real-world

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Joe Watkins
Hi Marco, What do you mean by "meaningful benchmarks" ? There's no question that is_initialized will be faster than the reflector version, even with reflection caching. Here's a naive bench: https://gist.github.com/krakjoe/cef6452281624bdf1b46788f52a01521 krakjoe@Fiji:/opt/src/php-src$ sapi/cli

Re: [PHP-DEV] Consensus Gathering: is_initialized

2021-05-26 Thread Marco Pivetta
On Wed, May 26, 2021 at 12:14 PM Joe Watkins wrote: > Hi internals, > > In response to: https://bugs.php.net/bug.php?id=78480 > > I implemented: https://github.com/php/php-src/pull/7029 > > Not absolutely convinced that it's a good idea, I asked Nikita to review, > and he's unconvinced also and s