raigu/php80-stringable-polyfill

Polyfill to backport PHP8.0 Stringable feature to lower PHP versions

v1.0.0 2020-04-19 17:57 UTC

This package is auto-updated.

Last update: 2024-04-28 21:17:06 UTC


README

Latest Stable Version GitHub license

Plyfill of Stringable interface of PHP8.0 to PHP7.4+

Allows to use Stringable interface, which will be in PHP8.0, in PHP7.4+.

Motivation

Current polyfill in sympfony/polyfill did not meet my needs.

First it did not follow explicitly the same interface signature (link) as in proposal (return type missing).

Secondly I discovered from __toString documentation that it was not possible to throw an exception from within a __toString() method before PHP 7.4.0. Doing so will result in a fatal error. The symphony/polyfill does not warn about it and allows to use polyfill starting from PHP 7.0.8. This package is explicit about this restriction in composer.json thus avoiding misuse.

Install

$ composer require raigu/php80-stringable-polyfill

License

This project is licensed under the MIT license

Acknowledgments

I would like to thank Guilliam Xavier for posting alternative names to Stringable interface. Although his recommendations where not accepted Google picked up the keywords. I was solving the same problem and where checking up my name candidates when I stumbled to Guilliam's post. Instead of continuing my own now I can create future compatible solutions that are easier to justify.