Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 761 Bytes

StringableTrait.md

File metadata and controls

41 lines (30 loc) · 761 Bytes

Docs / String / StringableTrait

Trait that implements the Stringable interface. Allows string conversion of class to string output.

Trait synopsis

trait StringableTrait
{
    use TypeTrait;

    // Stringable interface implementation.

    /**
     * Return string representation.
     * @return string String representation.
     */
    public function __toString(): string;
}

Examples

use Phrity\O\String\StringableTrait;

class MyClass implements Stringable
{
    use StringableTrait;

    public function __construct(string $input)
    {
        $this->initialize($input);
    }
}

$class = new MyClass("hey");
echo $class; // => "hey"