Skip to content

Commit 25d3a02

Browse files
committed
fix(ci) fix php8.5 Warning: unexpected NAN value was coerced to string
When binding a NAN value to a prepared statement parameter, PHP 8.5 emits a warning: "unexpected NAN value was coerced to string". This warning is not present in PHP 8.4, where the value was silently converted to the string "NAN" and handled correctly by PostgreSQL. @see https://wiki.php.net/rfc/warnings-php-8-5#coercing_nan_to_other_types
1 parent ae65d8c commit 25d3a02

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tests/Fixtures/TestBundle/Document/ResourceWithFloat.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ public function getId(): ?int
3333
return $this->id;
3434
}
3535

36-
public function getMyFloatField(): float
36+
public function getMyFloatField(): string|float
3737
{
38-
return $this->myFloatField;
38+
// php 8.5 emits warning unexpected NAN value was coerced to string
39+
// with symfony serializer
40+
// @see https://github.com/symfony/symfony/pull/62740
41+
return is_nan($this->myFloatField) ? 'NAN' : $this->myFloatField;
3942
}
4043

4144
public function setMyFloatField(float $myFloatField): void

tests/Fixtures/TestBundle/Entity/ResourceWithFloat.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,26 @@ class ResourceWithFloat
2828
#[ORM\GeneratedValue(strategy: 'AUTO')]
2929
private ?int $id = null;
3030
#[ORM\Column(type: 'float')]
31-
private float $myFloatField = 0.0;
31+
private string|float $myFloatField = 0.0;
3232

3333
public function getId(): ?int
3434
{
3535
return $this->id;
3636
}
3737

38-
public function getMyFloatField(): float
38+
public function getMyFloatField(): string|float
3939
{
40-
return $this->myFloatField;
40+
// php 8.5 emits warning unexpected NAN value was coerced to string
41+
// with symfony serializer
42+
// @see https://github.com/symfony/symfony/pull/62740
43+
return is_nan($this->myFloatField) ? 'NAN' : $this->myFloatField;
4144
}
4245

4346
public function setMyFloatField(float $myFloatField): void
4447
{
45-
$this->myFloatField = $myFloatField;
48+
// When binding a NAN value to a prepared statement parameter with Doctrine,
49+
// PHP 8.5 emits a warning: "unexpected NAN value was coerced to string".
50+
// @see https://github.com/doctrine/dbal/pull/7249
51+
$this->myFloatField = is_nan($myFloatField) ? 'NAN' : $myFloatField;
4652
}
4753
}

0 commit comments

Comments
 (0)