Re: [Proposal] Struct Data Types

From: Date: Fri, 15 Mar 2019 15:16:08 +0000
Subject: Re: [Proposal] Struct Data Types
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-104748@lists.php.net to get a copy of this message
Personally, I think pass by-value with copy-on-write semantics like arrays is the sweet spot. Mutability is fine if it is localized. I think having a no-constructor construction syntax is also a good idea. I've discussed it with a few people, but don't can't remember if it's ever been brought up on-list. Basically, the idea is to use a JSON-like syntax with the type-name in front, and I think it can be fine to use on regular classes that don't have a constructor too: struct Point2d { float $x; float $y; } $origin = Point2D { x: 0, y: 0 }; This syntax has no conflicts. We could also add an object literal syntax for creating ad-hoc stdClass objects like so: `$obj = { x: 1, y: 1}`. This has an ambiguity, but I believe I have solved the issue without too much trouble once before. I think structs, pass by-value with copy-on-write, and brace construction would go really well together.

« previous php.internals (#104748) next »