Skip to content

Commit 18f9677

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 6b95fc6 commit 18f9677

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

tests/Fixtures/TestBundle/Entity/ResourceWithFloat.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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
{
@@ -37,11 +37,13 @@ public function getId(): ?int
3737

3838
public function getMyFloatField(): float
3939
{
40-
return $this->myFloatField;
40+
return $this->myFloatField === 'NAN' ? \NAN : $this->myFloatField;
4141
}
4242

4343
public function setMyFloatField(float $myFloatField): void
4444
{
45-
$this->myFloatField = $myFloatField;
45+
// When binding a NAN value to a prepared statement parameter with Doctrine,
46+
// PHP 8.5 emits a warning: "unexpected NAN value was coerced to string".
47+
$this->myFloatField = is_nan($myFloatField) ? 'NAN' : $myFloatField;
4648
}
4749
}

0 commit comments

Comments
 (0)