> On May 6, 2019, at 09:37, Steven Wade <firstname.lastname@example.org> wrote:
> That being said, adding an interface like `ArraySerializable` might be nice too. I'm seeing technical arguments against adding magic casts, but (just spit-balling here), what if a class implemented a new `ArraySerializable` interace with whatever method it demands, and if that is attempted to be cast to an array either manually by calling "(array) $foo" or PHP attempting to, then the array serialize method is called. Â¯\_(ã)_/Â¯
Thatâs how I would prefer to see it work.
BTW, Iâm not suggesting `ArraySerializable` as the name. I used that to make a connection to `JsonSerializable`, which I think did a good job of using an interface for this kind of thing (even though itâs not quite the same because thereâs no cast for a JSON type).
In some of my open source projects, Iâve had to add `__toString()` to the interfaces to ensure that implementers implement it. It would be nice for my interfaces to instead extend an internal interface like `Stringable`.