Trait that implements the Stringable interface.
Allows string conversion of class to classname
(namespace is excluded).
Trait synopsis
trait StringableTrait
{
use TypeTrait;
// Stringable interface implementation.
/**
* Return string representation.
* @return string String representation.
*/
public function __toString(): string;
}
Examples
use Phrity\O\Object\StringableTrait;
class MyClass implements Stringable
{
use StringableTrait;
public function __construct(object $input)
{
$this->initialize($input);
}
}
$class = new MyClass((object)["a" => 1]);
echo $class; // => "MyClass"
Requirements
- PHP
^8.0