Kenneth Ellis McCall wrote:
Hey all,

I'm looking to get feedback on a RFC I want to propose.

PHP RFC: Addition of the 'struct' data type.


Hey all,

Hopefully this addresses the questions you had in someway, even if it's not a direct answer and might propose other things. Also sorry for the brevity.

Immutability:
My initial thought was to have the property list be immutable, such as you can't add or remove properties, but could change the value.
Maybe it would be possible to do something like this:

const Acme\MyStruct $myStruct = {
...
};

To make just the instance of the struct be fully immutable.

Other options could be another type, say constStruct (say that ten times fast), or maybe add a const hint type (or readonly) to the properties, like:

struct Acme\MyStruct {
   const int id;
}



Access:
I think I'm leaning towards the arrow accessors.


Making it more of class type:
Initial thinking, and why I thought we would need this, is that I would like a way to not use class objects for data bags (like that you see with entities), since you can abuse classes (and arrays) like this:

class xyz {

};

$a = new xyz();
$a->def = 123;

// Returns 123.
echo $a->def;

While people shouldn't do it, but because they can, they will.

Types hints:
I think having them on the left side would be the best, since it kind of matches what we already do. As for the loosely type properties, I'm kind of on the border on that. I really want to have strongly / statically typed hints, so it could enforce some better habits. On the other side, for historical purposes... Would definitely want to take a consensus on this.


Validation:
I have another item I want to bring up, but don't think it would go over well: https://github.com/ellisgl/PHP-RFC-Advanced-Type-Hint-Validors


Array / Class features:
When I wrote, 'resembles a mix of a class and an array' I was thinking loosely around the styling, accessing properties and errors.


Copy on Write or pass by reference/value:
I think I'm more with Levi with the "pass by-value with copy-on-write semantics", of course, since this is still draft mode, it could go another way after further investigation and testing during implementation.

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

Reply via email to