2023-05-06 12:55 GMT+02:00, Olle Härstedt <olleharst...@gmail.com>: > Heyo internalitos, > > I was thinking of having the possibility to use `readonly` (or any > other keyword) to make a function argument behave as if it was a > readonly object. > > class Point > { > public int $x; > public int $y; > } > function doThing(readonly Point $p) > { > $p->x = 10; // Not allowed > } > > In C# it's called in/out/ref types: > https://www.pluralsight.com/guides/csharp-in-out-ref-parameters > > The main use-case is to not give away more access than you have to, > and being able to state your intent in the function signature. > > Another alternative would be to allow properties in interfaces, and > then define a readonly-like interface: > > interface ReadonlyPoint > { > public readonly int $x; > public readonly int $y; > } > function doThing(ReadonlyPoint $p) > { > $p->x = 10; // Not allowed > } > > No idea about practical feasability. > > Since arrays are value types, they're not really relevant for this > suggestion. Same goes for string, int, etc. > > Regards > Olle
Also related is Object.freeze from JS (I was told): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze Olle -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php