mawebdk/to-string-builder

Builder class for __toString() methods.

Installs: 3

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mawebdk/to-string-builder

2.0.1 2025-09-04 15:17 UTC

This package is not auto-updated.

Last update: 2025-10-30 16:02:41 UTC


README

Builder class for __toString() methods.

Usage

Sample usage in a __toString() method:

public function __toString(): string
{
    $toStringBuilder = new ToStringBuilder(object: $this);
    
    return $toStringBuilder
        ->add('firstname', $this->firstname)
        ->add('lastname', $this->lastname)
        ->add('age', $this->age)
        ->build();
    }
}

Sample output:

Namespace\Classname{"firstname": "John", "lastname": "Doe", "age": 18}