Re: [RFC] Object Initializer

From: Date: Thu, 12 Sep 2019 15:01:13 +0000
Subject: Re: [RFC] Object Initializer
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-106969@lists.php.net to get a copy of this message
On Thu, Sep 12, 2019 at 4:00 PM Michał Brzuchalski < michal.brzuchalski@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 required constructor arguments as > a single expression with initializer block. > > https://wiki.php.net/rfc/object-initializer > > I appreciate any feedback you all can provide. > > Thanks, > -- > Michał Brzuchalski > brzuchal@php.net > > 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 = []; foreach ($peopleFromDatabase as [$id, $username, $name]) { $people[] = { Uuid id => $id, string username => $username, string name => $name, }; // and possible automatic assignment: $people[] = {Uuid $id, string $username, string $name}; } ``` Regards, Lynn van der Berg

« previous php.internals (#106969) next »