Re: [PHP-DEV] [RFC] Object Initializer

2019-10-07 Thread Michał Brzuchalski
Hi Arvids, sorry for the late response, I've been busy recently. wt., 17 wrz 2019 o 13:08 Arvids Godjuks napisał(a): > > I've have been keeping up with the thread and at this point, I do somewhat > agree with people that maybe the RFC should go into V2 version development. > It really seems

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-17 Thread Arvids Godjuks
чт, 12 сент. 2019 г. в 16:00, Michał Brzuchalski < michal.brzuchal...@gmail.com>: > Hi internals, > > I'd like to open discussion about RFC: Object Initializer. > > This proposal reduces boilerplate of object instantiation and properties > initialization in case of classes without required

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-16 Thread Arnold Daniels
Features like `func_get_args(ARGS_OBJECT)` and `hoist` aren't really needed. You can use `get_defined_vars()` instead. Many of my classes have constructors like; public function __construct(int $foo, string $bar, bool $flag = false) { set_object_vars($this, get_defined_vars()); } FYI

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-16 Thread Michał Brzuchalski
Hi Paul, niedz., 15 wrz 2019 o 15:48 Paul M. Jones napisał(a): > > > > On Sep 12, 2019, at 09:00, Michał Brzuchalski < > michal.brzuchal...@gmail.com> wrote: > > > > Hi internals, > > > > I'd like to open discussion about RFC: Object Initializer. > > > > This proposal reduces boilerplate of

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-15 Thread Paul M. Jones
> On Sep 12, 2019, at 09:00, Michał Brzuchalski > wrote: > > Hi internals, > > I'd like to open discussion about RFC: Object Initializer. > > This proposal reduces boilerplate of object instantiation and properties > initialization in case of classes without required constructor arguments

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Rowan Tommins
On 14/09/2019 09:49, Mike Schinkel wrote: But ironically I come to the exact opposite conclusion that your latter statements imply, i.e. that named parameters are not a generalizable enough feature and that object initializers are much more generalizable. I think that's only true because

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Larry Garfield
On Fri, Sep 13, 2019, at 9:35 AM, Rowan Tommins wrote: > Hi Rasmus, > > On Fri, 13 Sep 2019 at 11:18, Rasmus Schultz wrote: > > > All in all, I find this feature is useful or applicable only to a few, > > select patterns within the language - it isn't general enough. > > > > > I've trimmed

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Benjamin Eberlei
Hi Michal, thank you for this RFC. In combination with typed properties an object initializer syntax becomes highly thought after in my opinion, especially if you consider classes consisting mostly of typed PUBLIC properties, for example data transfer objects or view models. I find this

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Michał Brzuchalski
Hi Mike, sob., 14 wrz 2019 o 10:32 Mike Schinkel napisał(a): > > However, Object Initializers might be best when paired with a new magic > method which let us call *__init(),* and a *required* modifier for > properties. > > Using your Customer example, the __init() would be automatically called

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Michał Brzuchalski
Hi Sebastian, sob., 14 wrz 2019 o 11:05 Sebastian Bergmann napisał(a): > Am 13.09.2019 um 15:23 schrieb Matthew Brown: > > Though this is truly a stylistic complaint, I think it will lead to > > harder-to-analyse code. > > Fully agreed, and not just harder-to-analyse for a static analysis tool

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Sebastian Bergmann
Am 13.09.2019 um 15:23 schrieb Matthew Brown: Though this is truly a stylistic complaint, I think it will lead to harder-to-analyse code. Fully agreed, and not just harder-to-analyse for a static analysis tool but also for humans that read the code. -1 from me. -- PHP Internals - PHP

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Mike Schinkel
> On Sep 14, 2019, at 1:50 AM, Marco Pivetta wrote: Thank you for your reply. > lazy initialisation is already possible in userland: adding more magic to the > language for a use-case that is already implemented seems problematic to me. I think I am missing something. I was not aware I was

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Mike Schinkel
(Sorry for sending three replies to one message, but the list server said my reply was too long to send as just one. I could have made it shorter but then I would have had to omit all the example code.) @rasmus: HOWEVER, I see no reason we must pit object initializers and named parameters

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Marco Pivetta
On Sat, Sep 14, 2019 at 10:47 AM Mike Schinkel wrote: > > On Sep 13, 2019, at 3:18 AM, Rasmus Schultz ras...@mindplay.dk>> wrote: > > > > Assuming the fields of this entity are required, you would probably > prefer > > to add a constructor - but then property initializers aren't really > useful

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Mike Schinkel
> On Sep 13, 2019, at 3:18 AM, Rasmus Schultz > wrote: > > All in all, I find this feature is useful or applicable only to a few, > select patterns within the language - it isn't general enough. > ... > In my opinion, language features should be as general as possible

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-14 Thread Mike Schinkel
> On Sep 13, 2019, at 3:18 AM, Rasmus Schultz > wrote: > > Assuming the fields of this entity are required, you would probably prefer > to add a constructor - but then property initializers aren't really useful > anymore. I think this is a false dichotomy; I can see

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Rowan Tommins
Hi Rasmus, On Fri, 13 Sep 2019 at 11:18, Rasmus Schultz wrote: > All in all, I find this feature is useful or applicable only to a few, > select patterns within the language - it isn't general enough. > I've trimmed the quote for readability, but agree with basically everything in this

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Matthew Brown
Though this is truly a stylistic complaint, I think it will lead to harder-to-analyse code. Currently I have a static analysis tool that can verify (in 99% of cases) whether all properties of a class have been initialised in the constructor. This check is even more important in PHP 7.4, where use

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Arnold Daniels
On Fri, Sep 13, 2019 at 12:18 PM Rasmus Schultz wrote: > I'd like to address the examples - and why I think they don't demonstrate > that this feature is really useful in practice. > > There are several examples similar to this one: > > class Car > { > public int $yearOfProduction; > public

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Lynn
On Fri, Sep 13, 2019 at 10:51 AM Arnold Daniels < arnold.adaniels...@gmail.com> wrote: > Comments: > > I don't like how it works for anonymous classes. It's more difficult to > implement since the compiler doesn't know the meaning of the (first) > bracket. It's doesn't make the code more

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Rasmus Schultz
I'd like to address the examples - and why I think they don't demonstrate that this feature is really useful in practice. There are several examples similar to this one: class Car { public int $yearOfProduction; public string $vin; } This is either lacking a constructor to initialize the

Fwd: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Arnold Daniels
> I don't like how it works for anonymous classes. It's more difficult to >> implement since the compiler doesn't know the meaning of the (first) >> bracket. It's doesn't make the code more readable, for the same reason. I >> think it's better to not support this syntax with anonymous classes. >>

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
> On Sep 13, 2019, at 2:39 AM, Michał Brzuchalski > wrote: > $obj->foo => 123; > Simply, that's not the way you initialize object property values. So by the same logic this should be PHP's way to initialize array elements, right? $arr['foo'] => 123; But it is not. Obviously we both know that

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Michał Brzuchalski
pt., 13 wrz 2019 o 11:29 Mike Schinkel napisał(a): > IMO should stay specific for arrays only. > > > Why? Is there an objective reason? > > $obj->foo => 123; Simply, that's not the way you initialize object property values. When you use "=>" in array context you're pushing a new value to array

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
> IMO should stay specific for arrays only. Why? Is there an objective reason? Is there some aspect of the syntax that makes it appropriate for arrays but inappropriate for object initialization? These are honest question. My two cents: I would like to type less too, but I have always

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Michał Brzuchalski
Hi Mike, I am curious why your RFC uses "=" instead of "=>" for separating > properties from values? > > If we used "=>" it is potential — with lookahead parsing — that the > following could be unambiguous: > > { foo => 10 } > > The reason about choosing "=" was a simplification of instantiation

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Michał Brzuchalski
Hi Arnold, pt., 13 wrz 2019 o 10:51 Arnold Daniels napisał(a): > This can easily be done in a number of ways, like the suggested helper > function. The same can be said for many other features that were > implemented recently, like array unpacking. This feature is easy to > implement and will

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
Arnold, > This can easily be done in a number of ways, like the suggested helper > function. A helper function can simulate an object initializer but it cannot provide the same potential benefits. The helper function uses array keys to identify properties, and as array keys cannot be

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Arnold Daniels
This can easily be done in a number of ways, like the suggested helper function. The same can be said for many other features that were implemented recently, like array unpacking. This feature is easy to implement and will make the code for data objects much more readable, with additional benefits

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
> That said, I generally use arrays rather than DTO objects I too have often used arrays. But then I have always been rigorous to ensure that variables and array elements are initialized before use, and fortunately I do not have a lot of typos in code I write. However I recently took on a

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
> What's the added benefit of this compared to implementing a constructor? Michal my have a different answer but my answer are the following two benefits plus a 3rd related benefit: 1. The ability to add strictness to object initialization vs. using arrays of properties. PHP itself could flag

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Michał Brzuchalski
Hi Claude, pt., 13 wrz 2019 o 08:39 Claude Pache napisał(a): > > > Le 13 sept. 2019 à 07:49, Michał Brzuchalski > a écrit : > > Hi Lynn, > > czw., 12 wrz 2019 o 17:01 Lynn napisał(a): > > Heya, > > What's the added benefit of this compared to implementing a constructor? > > The part I like is

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Mike Schinkel
Hi Michal, > https://wiki.php.net/rfc/object-initializer I recently joined this list again after many years away, and a primary reason was to eventually propose an RFC that is almost exactly what you are calling Object Initializers. So a huge thumbs up on this RFC. Kudos. I wish I had a

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Claude Pache
> Le 13 sept. 2019 à 07:49, Michał Brzuchalski a > écrit : > > Hi Lynn, > > czw., 12 wrz 2019 o 17:01 Lynn mailto:kja...@gmail.com>> > napisał(a): > >> Heya, >> >> What's the added benefit of this compared to implementing a constructor? >> >> The part I like is that this can be used to

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-13 Thread Michał Brzuchalski
Hi Olumide, czw., 12 wrz 2019 o 17:07 Olumide Samson napisał(a): > The RFC is a beautiful feature suggestion, but something is telling me as > beautiful and straightforward the syntax is, what can the use case be? > > I really love Constructor or Object initialization to be implemented in >

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-12 Thread Michał Brzuchalski
Hi Lynn, czw., 12 wrz 2019 o 17:01 Lynn napisał(a): > Heya, > > What's the added benefit of this compared to implementing a constructor? > > The part I like is that this can be used to replace stdClass/structured > arrays. Perhaps something like this would nice to have in PHP: > > ``` > $people

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-12 Thread Olumide Samson
The RFC is a beautiful feature suggestion, but something is telling me as beautiful and straightforward the syntax is, what can the use case be? I really love Constructor or Object initialization to be implemented in PHP, but is there something I think you're missing in the RFC? Thanks for the

Re: [PHP-DEV] [RFC] Object Initializer

2019-09-12 Thread Lynn
On Thu, Sep 12, 2019 at 4:00 PM Michał Brzuchalski < michal.brzuchal...@gmail.com> wrote: > Hi internals, > > I'd like to open discussion about RFC: Object Initializer. > > This proposal reduces boilerplate of object instantiation and properties > initialization in case of classes without

[PHP-DEV] [RFC] Object Initializer

2019-09-12 Thread Michał Brzuchalski
Hi internals, I'd like to open discussion about RFC: Object Initializer. This proposal reduces boilerplate of object instantiation and properties initialization in case of classes without required constructor arguments as a single expression with initializer block.