spatie/better-types
Reflection-powered type checking for PHP: verify whether a ReflectionType or method signature accepts given arguments (including unions/nullables and named params). Useful for dispatching/overload-like method selection and safer dynamic calls.
Type Safety & Developer Experience (DX):
string|int) and named types (e.g., custom classes), aligning with modern PHP 8+ features.Build vs. Buy:
instanceof checks or regex validation).Roadmap Priorities:
FormRequest or API gateways).Use Cases:
Accepts: User|Admin).Email|PhoneNumber).Adopt if:
Look elsewhere if:
string|int checks).For Executives: "This package lets us enforce stricter type rules in our PHP/Laravel apps—catching bugs early and reducing runtime errors. It’s like adding a ‘compile-time guardrail’ for data validation, which cuts debugging time and improves API/form reliability. Low risk (MIT license, battle-tested by Spatie), high reward for developer productivity."
For Engineers:
*"Spatie’s better-types gives us a clean way to validate union/named types (e.g., User|Admin or custom classes) without manual instanceof spaghetti. Works seamlessly with Laravel’s validation, and the syntax is intuitive:
if (BetterType::isType($input, User::class | Admin::class)) { ... }
It’s a drop-in upgrade for type safety—no refactoring needed. Perfect for APIs, forms, or legacy systems where we want to modernize validation."*
How can I help you explore Laravel packages today?