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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to