Repository: symfony/symfony
File: src/Symfony/Component/Validator/Constraint.php (PHP)

Code before:
     * name of an existing property. If no associative array is passed, this
     * property is set instead.
     *
     * You can force that certain options are set by overriding
     * getRequiredOptions() to return the names of these options. If any
     * option is not set here, an exception is thrown.
     *
     * @param mixed    $options The options (as associative array)
     *                          or the value for the default
     *                          option (any other type)
     * @param string[] $groups  An array of validation groups
     * @param mixed    $payload Domain-specific data attached to a constraint
     *
     * @throws InvalidOptionsException       When you pass the names of non-existing
     *                                       options
     * @throws MissingOptionsException       When you don't pass any of the options
     *                                       returned by getRequiredOptions()
     * @throws ConstraintDefinitionException When you don't pass an associative
     *                                       array, but getDefaultOption() returns
     *                                       null
     */
    public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
    {
        unset($this->groups); // enable lazy initialization

        if (null === $options && ($this->areRequiredOptionsHandledByChildConstructor() || self::class === (new \ReflectionMethod($this, 'getRequiredOptions'))->getDeclaringClass()->getName())) {
            if (null !== $groups) {
                $this->groups = $groups;
            }
            $this->payload = $payload;

            return;
        }

        trigger_deprecation('symfony/validator', '7.4', 'Support for evaluating options in the base Constraint class is deprecated. Initialize properties in the constructor of %s instead.', static::class);

        $options = $this->normalizeOptions($options);
        if (null !== $groups) {
            $options['groups'] = $groups;
        }
        $options['payload'] = $payload ?? $options['payload'] ?? null;

        foreach ($options as $name => $value) {
            $this->$name = $value;
        }
    }

    /**
     * Checks whether the child class constructor has named parameters for each
     * required option, meaning it handles their validation itself.
     */

Review comment (suggestion):
I suppose the 2nd part it not needed anymore:
```suggestion
        if (null === $options && $this->areRequiredOptionsHandledByChildConstructor()) {
```

Code after:
     * name of an existing property. If no associative array is passed, this
     * property is set instead.
     *
     * You can force that certain options are set by overriding
     * getRequiredOptions() to return the names of these options. If any
     * option is not set here, an exception is thrown.
     *
     * @param mixed    $options The options (as associative array)
     *                          or the value for the default
     *                          option (any other type)
     * @param string[] $groups  An array of validation groups
     * @param mixed    $payload Domain-specific data attached to a constraint
     *
     * @throws InvalidOptionsException       When you pass the names of non-existing
     *                                       options
     * @throws MissingOptionsException       When you don't pass any of the options
     *                                       returned by getRequiredOptions()
     * @throws ConstraintDefinitionException When you don't pass an associative
     *                                       array, but getDefaultOption() returns
     *                                       null
     */
    public function __construct(mixed $options = null, ?array $groups = null, mixed $payload = null)
    {
        unset($this->groups); // enable lazy initialization

        if (null === $options && $this->areRequiredOptionsHandledByChildConstructor()) {
            if (null !== $groups) {
                $this->groups = $groups;
            }
            $this->payload = $payload;

            return;
        }

        trigger_deprecation('symfony/validator', '7.4', 'Support for evaluating options in the base Constraint class is deprecated. Initialize properties in the constructor of %s instead.', static::class);

        $options = $this->normalizeOptions($options);
        if (null !== $groups) {
            $options['groups'] = $groups;
        }
        $options['payload'] = $payload ?? $options['payload'] ?? null;

        foreach ($options as $name => $value) {
            $this->$name = $value;
        }
    }

    /**
     * @deprecated since Symfony 7.4
     *
     * @return array<string, mixed>