Skip to content

Simple Data ObjectsTyped PHP data objects, compiled for speed

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.

The whole idea in one screen ​

A data object is a class with typed constructor properties. Attributes describe anything that isn't obvious from the types.

Define it once

php
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

php
// 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 collection

Released under the MIT License.