Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104739 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57969 invoked from network); 15 Mar 2019 13:31:49 -0000 Received: from unknown (HELO mail4.serversure.net) (185.153.204.204) by pb1.pair.com with SMTP; 15 Mar 2019 13:31:49 -0000 Received: (qmail 19718 invoked by uid 89); 15 Mar 2019 10:22:25 -0000 Received: by simscan 1.3.1 ppid: 19708, pid: 19715, t: 0.1976s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.7?) (lester@lsces.co.uk@81.138.11.136) by mail4.serversure.net with ESMTPA; 15 Mar 2019 10:22:25 -0000 To: internals@lists.php.net References: <5c8b20b5.1c69fb81.d9f23.2cacSMTPIN_ADDED_MISSING@mx.google.com> Message-ID: <73a36df6-d385-0026-65ad-e8de07b65c23@lsces.co.uk> Date: Fri, 15 Mar 2019 10:22:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [Proposal] Struct Data Types From: lester@lsces.co.uk (Lester Caine) On 15/03/2019 09:54, Nikita Popov wrote: > could then become something like > > // declaration > class AnotherStruct { > readonly string $firstName; > readonly string $lastName; > readonly ?int $age = null; > } > // initialization (syntax up to bikeshedding) > new AnotherStruct { > $firstName => 'Little', > $lastName => 'Johnny', > $age => 5, > } > > I'd generally prefer a solution that is based on the existing class system. > Especially as it means that other use-cases can also benefit: Sometimes you > might only want some of your properties to be readonly, etc. There is also more room to add formal validation so we could have class AnotherStruct { readonly string(64) $firstName; readonly string(64) $lastName; readonly ?int(0-150) $age = null; } Although I would perhaps expect in this case to have 'date of birth' as 'immutable' while age is something that will be variable. But isn't all this just mainly another class object. As has been suggested for an improved array object but never developed further? Create an extension to support it first, although the validation element is still needed for any variable across the board ... -- Lester Caine - G8HFL ----------------------------- Contact - https://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - https://lsces.co.uk EnquirySolve - https://enquirysolve.com/ Model Engineers Digital Workshop - https://medw.co.uk Rainbow Digital Media - https://rainbowdigitalmedia.co.uk