ToStringTrait uses \oihana\reflect\traits\ReflectionTrait
Provides a basic string representation for an object by returning its class name wrapped in square brackets or other defined characters.
This trait uses reflection to dynamically obtain the short class name of the object.
It also caches the result for performance on repeated calls to __toString()
.
Methods:
- __toString(): Returns a string like "[ClassName]".
Example usage:
use oihana\traits\ToStringTrait;
class MyObject {
use ToStringTrait;
}
echo (new MyObject()); // Output: [MyObject]
Table of Contents
Methods
- __toString() : string
- Returns a String representation of the object.
Methods
__toString()
Returns a String representation of the object.
public
__toString() : string
Tags
Return values
string —A string representation of the object.