> On May 6, 2019, at 09:37, Steven Wade <stevenwad...@gmail.com> 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`.

-Ben

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to