Skip to content

Conversation

janedbal
Copy link
Contributor

@janedbal janedbal commented Apr 24, 2024

Probably fixes even phpstan/phpstan#10125

Warning: A non-numeric value encountered on phar:///home/honza/Development/shipmonk/phpstan-rules/vendor/phpstan/phpstan/phpstan.phar/src/Type/ExponentiateHelper.php:72 

Found in https://github.com/shipmonk-rnd/phpstan-rules tests when run with new 204ab27

$result = $base->getValue() ** $exponent->getValue();
try {
// @ to avoid "Warning: A non-numeric value encountered"
$result = @pow($base->getValue(), $exponent->getValue()); // @phpstan-ignore-line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather prevent the problem by checking the type of the values instead of silencing the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require some crazy regexes. I dont think there is a simple way to simulate the magical numeric-string behaviour: https://3v4l.org/ECZjp#v8.3.6

This way we are sure we get exactly what PHP evalutes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like is_numeric would do the job: https://3v4l.org/sYolO#v8.3.6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, those are both numeric, but results in different output type: https://3v4l.org/aDslS#v8.3.6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar open PR you might can get inspiration from

#2796

@ondrejmirtes
Copy link
Member

Superseded by #2796

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants