[PR #9535] Leverage the Stringable interface #11687

Open
opened 2026-01-22 16:11:36 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/9535

State: closed
Merged: Yes


In PHP 8, classes that implement the __toString() method automagically implement a new interface called Stringable. This means that we can rewrite method_exists() checks for __toString() to instanceof checks.

We could also consider announcing the Stringable interface explicitly on our own classes with a __toString() method. But that would be pure documentation because, as already mentioned, PHP will add the interface whether we announce it or not.

**Original Pull Request:** https://github.com/doctrine/orm/pull/9535 **State:** closed **Merged:** Yes --- In PHP 8, classes that implement the `__toString()` method automagically implement a new interface called `Stringable`. This means that we can rewrite `method_exists()` checks for `__toString()` to `instanceof` checks. We could also consider announcing the `Stringable` interface explicitly on our own classes with a `__toString()` method. But that would be pure documentation because, as already mentioned, PHP will add the interface whether we announce it or not.
admin added the pull-request label 2026-01-22 16:11:36 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11687