Version 2.0 is a breaking release that fixes long-standing bugs and tightens the API. Most existing rule strings keep working unchanged; the breaking changes are about PHP version, error behaviour and a few corrected edge cases.
- PHP 8.1 or newer is now required (1.x supported 7.4+).
In 1.x a misspelled or unknown rule was silently ignored and the field counted
as valid. In 2.0 it throws UndefinedRuleException.
$v->rule('age', 'integerr'); // 1.x: silently passes — 2.0: throwsFix any typos, and register custom names with extend().
In 1.x a rule name that matched a global function (e.g. ctype_digit) was
invoked with the field value. This was surprising and unsafe and has been
removed. Such names now throw UndefinedRuleException. Wrap the logic in a
callback or extend() instead:
$v->extend('ctype_digit', static fn ($value): bool => ctype_digit((string) $value));Passing a callback as the rule used to throw a TypeError. It now works as
documented:
$v->rule('number', static fn ($value): bool => ($value % 2) === 0, '{field} must be even.');- The
againrule now resolves its English message (it previously fell back to the generic "not valid" text). - Message keys resolve case-insensitively, so writing
creditcardorcreditCardproduces the same message. - The Turkish
notContainsmessage now reads "must not contain".
If you relied on the old (incorrect) message strings in tests, update those expectations.
These were bugs; the new behaviour is what the documentation always implied:
- Arguments are trimmed, so
only(a, b, c)matches the same way asonly(a,b,c). - Open-ended
lengthworks:length(...255)now enforces the maximum. lengthon anullvalue returnsfalseinstead of raising a warning.min/maxon arrays measure the element count without a type warning.equalsandagaincompare loosely, soequals(123)matches the integer123.
setLocale() / setLocaleDir() now throw InitPHP\Validation\Exception\LocaleException
(previously \InvalidArgumentException / \Exception), and rule() throws
InitPHP\Validation\Exception\InvalidArgumentException. All package exceptions
implement InitPHP\Validation\Exception\ExceptionInterface. If you catch the
SPL types, note that InvalidArgumentException still extends
\InvalidArgumentException; the locale errors now need the new type or the
marker interface.
extend()for reusable custom named rules.getData()accessor.- An
alphanumericalias foralphanum. - Typed signatures, full PHPDoc, PHPStan (max) and PSR-12 compliance.
- Bump your PHP requirement to 8.1+.
- Search your rule strings for typos and any global-function names.
- Update tests that asserted old message text.
- Catch the new exception types where you load locales.