Turn input into objects
Arrays, JSON, requests, Eloquent models — one from() call gives you a typed, immutable object.
Hydration
Up to 60× faster than the most popular alternative, with the same attribute-driven classes. Hydration, validation, casting and serialization — no boilerplate, no runtime reflection. PHP 8.4+, plain PHP or Laravel 12–13.
A data object is a class with typed constructor properties. Attributes describe anything that isn't obvious from the types.
Define it once
use StdOut\SimpleDataObjects\BaseData;
use StdOut\SimpleDataObjects\Attributes\{Cast, Rules};
use StdOut\SimpleDataObjects\Casts\DateTimeCast;
class UserData extends BaseData
{
public function __construct(
#[Rules(['required', 'string', 'max:120'])]
public readonly string $name,
#[Rules(['required', 'email'])]
public readonly string $email,
#[Cast(new DateTimeCast('Y-m-d'))]
public readonly ?DateTime $birthday = null,
) {}
}Use it everywhere
// from an array, JSON, a request, a model…
$user = UserData::from($request->all());
// …validated first, if you want
$user = UserData::fromValidated($payload);
$user->name; // typed, autocompleted
$user->birthday?->format('d M');
$user->toArray(); // back to plain data
$user->with(name: 'Alice'); // a modified copy
UserData::collection($rows); // typed collectionSpeed is the reason this library exists, not a side effect. Three decisions account for it.