Skip to content

Commit 3f20608

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 3f20608

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/Fixtures/TestBundle/Entity/ResourceWithFloat.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ 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+
return is_nan($this->myFloatField) ? '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)