Re: Proposal for a RFC
| From: | Ben Ramsey | Date: | Mon, 06 May 2019 14:45:04 +0000 |
| Subject: | Re: Proposal for a RFC | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105599@lists.php.net to get a copy of this message | ||
> On May 6, 2019, at 09:37, Steven Wade <stevenwadejr@gmail.com> wrote:
>
> That being said, adding an interface like
Attachment: [application/pgp-signature] Message signed with OpenPGP signature.asc
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: [application/pgp-signature] Message signed with OpenPGP signature.asc