|
8 | 8 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
9 | 9 |
|
10 | 10 | use function assert;
|
| 11 | +use function ctype_digit; |
11 | 12 | use function is_int;
|
12 | 13 | use function is_string;
|
13 |
| -use function preg_replace; |
14 | 14 | use function rtrim;
|
| 15 | +use function str_starts_with; |
15 | 16 | use function strpos;
|
16 | 17 | use function substr;
|
17 | 18 |
|
@@ -53,13 +54,27 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): int
|
53 | 54 | 'DBAL assumes values outside of the integer range to be returned as string by the database driver.',
|
54 | 55 | );
|
55 | 56 |
|
56 |
| - // workaround https://github.com/php/php-src/issues/14345 |
| 57 | + if (str_starts_with($value, '-') || str_starts_with($value, '+')) { |
| 58 | + $hasNegativeSign = str_starts_with($value, '-'); |
| 59 | + $value = substr($value, 1); |
| 60 | + } else { |
| 61 | + $hasNegativeSign = false; |
| 62 | + } |
| 63 | + |
| 64 | + while (substr($value, 0, 1) === '0' && ctype_digit(substr($value, 1, 1))) { |
| 65 | + $value = substr($value, 1); |
| 66 | + } |
| 67 | + |
57 | 68 | $dotPos = strpos($value, '.');
|
58 | 69 | if ($dotPos !== false && rtrim(substr($value, $dotPos + 1), '0') === '') {
|
59 | 70 | $value = substr($value, 0, $dotPos);
|
60 | 71 | }
|
61 | 72 |
|
62 |
| - if (preg_replace('~^(\+|-(?=0+$))|(?<=^|^[+\-])0+(?=\d)~', '', $value) === (string) (int) $value) { |
| 73 | + if ($hasNegativeSign && $value !== '0') { |
| 74 | + $value = '-' . $value; |
| 75 | + } |
| 76 | + |
| 77 | + if ($value === (string) (int) $value) { |
63 | 78 | return (int) $value;
|
64 | 79 | }
|
65 | 80 |
|
|
0 commit comments