Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined array key "message" on ValidationAnnotation->extractFromConstraints() while use constructor promoted properties #174

Open
SinErgy84 opened this issue Feb 19, 2024 · 1 comment

Comments

@SinErgy84
Copy link

SinErgy84 commented Feb 19, 2024

Hi!

I have discovered an error in the following class:

/var/www/vhosts/abc/vendor/php-translation/extractor/src/Visitor/Php/Symfony/ValidationAnnotation.php:112 Warning: Undefined array key "message"
#0 /var/www/vhosts/abc/vendor/php-translation/extractor/src/Visitor/Php/Symfony/ValidationAnnotation.php(91): Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation->extractFromConstraints()

while using constructor promoted properties instead a class var for $message.

During debugging I found following behaviour:

The reflection class of

    public function __construct($options = NULL, array $groups = NULL, $payload = NULL, public string $message = 'validatoren.adresse.ungueltig', public string $message_connection_error = 'validatoren.adresse.connection')
    {
        parent::__construct($options, $groups, $payload);
    }

does not provide message as default properties so they are missing while dumping

$ref = new \ReflectionClass($constraint);
$defaultValues = $ref->getDefaultProperties();

see:
image

If you declare $message the old school way as class var:

public string $message = 'validatoren.adresse.ungueltig';

    public function __construct($options = NULL, array $groups = NULL, $payload = NULL, public string $message_connection_error = 'validatoren.adresse.connection')
    {
        parent::__construct($options, $groups, $payload);
    }

the default properties of the reflection class does contains message as array key and there is no warning during extraction:

image

A discussion about this behaviour as an potential php bug you can find here: https://bugs.php.net/bug.php?id=81386&edit=1

Not using constructor promoted properties as an PHP8 feature is not a solution for this issue.

@bocharsky-bw
Copy link
Member

Yeah, sounds like a problem related to the new PHP 8 syntax. It would be great to work around it IMO, do you want to give it a try? Even if that fixed in a newer version of PHP - it still would be a problem for legacy PHP versions, so a good workaround would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants