.. _classes-couldbestringable: .. _could-be-stringable: Could Be Stringable +++++++++++++++++++ ``Stringable`` is an interface that marks classes with a custom method to cast the object as a string. It was introduced in PHP 8.0. Classes that defined a `__toString() `_ magic method may be turned into a string when the typehint, argument, return or property, requires it. This is not the case when strict_types is activated. Yet, until PHP 8.0, there was nothing to identify a class as such. .. code-block:: php See also `PHP RFC: Add Stringable interface `_ and `The Stringable interface `_. Suggestions ___________ * Add implements stringable to the class definition * Add extends stringable to the interface definition Specs _____ +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Short name | Classes/CouldBeStringable | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Class Review `, :ref:`LintButWontExec `, :ref:`PHP recommendations ` | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 2.1.9 | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | PHP Version | With PHP 8.0 and more recent | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Features | stringable, string, magic-method | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Note | This issue may lint but will not run | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+