Symfony 8.2 is in beta (BETA2 shipped on 13 November 2026), and the team is publishing a “New in Symfony 8.2” post for each feature. The Validator improvements post from 13 November is one of the most practical for everyday PHP work. It brings inline callback rules, Unique on objects, BcMath\Number support, and better control over group sequences and cascading. This tutorial explains each change with code you can adapt, and what to test before 8.2 is final.
Try it on the beta
composer require symfony/validator:^8.2@beta
# or, in a full Symfony app, allow beta releases and update all symfony/* packages
Symfony 8 needs a recent PHP version. The inline closure examples below also need PHP 8.5, because that is the version that allows static closures in constant expressions such as attribute arguments.
1. Inline rules with Callback + message
Before 8.2, a custom rule with Callback meant writing a method, getting the execution context and building the violation yourself. In 8.2, Callback has a message option. When it is set, your callback just returns true or false, and Symfony creates the violation when it returns false.
With PHP 8.5 you can keep the whole rule inside the attribute:
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class Order
{
#[Assert\Callback(
static function (\DateTimeImmutable $value): bool {
return $value > new \DateTimeImmutable('today');
},
message: 'The delivery date must be in the future.',
)]
public \DateTimeImmutable $deliveryDate;
public int $subtotal;
#[Assert\Callback(
static function (int $value, ExecutionContextInterface $context): bool {
return $value >= $context->getObject()->subtotal;
},
message: 'The total must be greater than or equal to the subtotal.',
)]
public int $total;
}
The closure receives the same arguments as before, so you can still reach the parent object through the context.
When to use it: one-off rules that only make sense on one property. If you reuse a rule across classes, a proper custom constraint and validator class is still easier to test and document.
2. Unique now works with collections of objects
The fields option of Unique checks uniqueness using only some fields, but until now it only worked for arrays of arrays. In 8.2 it also works for arrays of objects:
use Symfony\Component\Validator\Constraints as Assert;
class Cart
{
/** @var CartItem[] */
#[Assert\Unique(fields: ['sku'])]
public array $items = [];
}
Public properties are read directly. Everything else goes through the PropertyAccess component, so getters and property paths work too. That means you can delete the hand-written “no duplicate SKU” loops that many DTOs carry around.
3. Arbitrary precision numbers with BcMath\Number
PHP 8.4 added the BcMath\Number class for arbitrary precision maths, which money and exchange-rate code needs. In 8.2, Range and the comparison constraints (EqualTo, NotEqualTo, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual) accept these values:
use BcMath\Number;
use Symfony\Component\Validator\Constraints as Assert;
class Payment
{
#[Assert\Range(min: 0.01, max: 10000)]
public Number $amount;
#[Assert\GreaterThanOrEqual('0.0001')]
public Number $exchangeRate;
}
There is a trap that Symfony handles for you. In plain PHP, comparing a BcMath\Number with a float truncates the float to an integer, so new Number('10.2') > 10.5 is true. Symfony converts the limits to BcMath\Number before comparing, so both sides keep their precision.
Tip: write limits as strings ('0.0001') when precision matters. Floats like 0.1 cannot be stored exactly, even before Symfony converts them.
4. Non-string violation parameters
In custom validators, setParameter() used to accept only strings, while setParameters() accepted anything. In 8.2, setParameter() accepts string, int, float, \Stringable and \DateTimeInterface. That works well with ICU message formats, which can format dates and numbers for each locale:
# translations/validators+intl-icu.en.yaml
booking.too_late: 'Bookings must be made before {deadline, date, long}.'
$this->context->buildViolation('booking.too_late')
->setParameter('deadline', $booking->getEvent()->getStartsAt())
->addViolation();
You no longer need to call format() yourself, and each locale gets the right date format.
5. Group sequences: ::class and cascadeCurrentGroup
Group sequences validate a class step by step. Two improvements land in 8.2.
Use ::class for the class’s own group. Before, you wrote the short class name as a string ('Order'), which broke quietly when you renamed the class. Now you can use Order::class.
Cascade the current group into nested objects. Before, objects marked with Valid were validated only against the Default group inside a sequence, so their constraints in other groups never ran. The new cascadeCurrentGroup option fixes that:
use Symfony\Component\Validator\Constraints as Assert;
#[Assert\GroupSequence([Order::class, 'Shipping'], cascadeCurrentGroup: true)]
class Order
{
// Address constraints in the 'Shipping' group now run
// during the 'Shipping' step of the sequence
#[Assert\Valid]
public Address $shippingAddress;
}
The option also works in YAML and XML, and with #[Assert\GroupSequenceProvider] for classes that compute their sequence at runtime.
6. More flexible cascading with Valid
The groups option of Valid did two jobs: it decided when to validate the nested object and which of its constraints to check. That made reusable nested objects awkward. The new restrictGroups: false option uses the groups only as a trigger:
use Symfony\Component\Validator\Constraints as Assert;
class Order
{
#[Assert\Valid(groups: ['alternateInvoiceAddress'], restrictGroups: false)]
public Address $invoiceAddress;
}
// the address is validated only when 'alternateInvoiceAddress' is requested,
// and then it is checked against all requested groups
$validator->validate($order, null, ['Default', 'alternateInvoiceAddress']);
Valid can now also sit inside Sequentially. That helps when a value can have more than one shape and you only want to cascade after a type check passes:
#[Assert\Sequentially([
new Assert\Type(Product::class),
new Assert\Valid(),
])]
public mixed $payload;
The nested Valid can’t define its own groups here. Set them on Sequentially instead.
How to test before 8.2 is final
- Create a branch, allow beta packages and update
symfony/*. - Run your validation tests. Look for new violations if you use group sequences together with
Valid, becausecascadeCurrentGroupis opt-in but you may want to turn it on. - Replace hand-written duplicate checks with
Unique(fields: [...])and keep the tests that cover them. - If you handle money, move amounts to
BcMath\Numberand string limits, and test edge values such as0.01and9999.99. - Report any regressions to the Symfony issue tracker while the release is still in beta.
Takeaway
Symfony 8.2’s validator changes remove boilerplate (inline callbacks, object Unique), fix real correctness problems (BcMath\Number comparisons, cascading in group sequences) and make messages easier to translate. Try them on the beta now so your app is ready on release day. Source: New in Symfony 8.2: Validator Improvements.
