Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ There have been several attempts to introduce a standard `toArray` method or int
- The first attempt was in 2012, when an [RFC proposed adding several magic methods to PHP, including `__toArray`, `__toInt()`, `__toFloat()`, `__toScalar()`, and `__toBool()`](https://wiki.php.net/rfc/object_cast_to_types). This proposal failed before reaching the voting stage due to concerns about implementation details and lack of consensus.
- In 2019, a separate [RFC specifically focused on introducing only a `__toArray` method for objects](https://wiki.php.net/rfc/to-array). Unlike the broader 2012 proposal, this RFC aimed to standardize array conversion alone, but it also failed before reaching the voting stage due to lack of support and unresolved concerns—particularly that the `__toArray` method did not specify what kind of array should be returned (e.g., associative or indexed), nor whether nested arrays or objects were allowed as values. One of the main unresolved questions was how to specify or standardize the format of the returned array in a way that would suit all use cases.
- Over the years, various frameworks and libraries (such as [Laravel's illuminate/contracts](https://packagist.org/packages/illuminate/contracts)) have introduced their own `toArray` conventions, but these are not universal and often come with additional dependencies.
- As of now, neither PHP itself nor the PHP-FIG group has adopted an official standard for object-to-array conversion.
- As of now, neither PHP itself nor the [PHP-FIG group](https://www.php-fig.org/psr/) has adopted an official standard for object-to-array conversion.

This package was created to address this gap: it provides a minimal Composer package containing only the `ToArrayInterface`. Use it when you need to ensure an object can be converted to an array via a `toArray` method, without introducing unnecessary dependencies.

Expand Down