Skip to content

PDO with pgsql changed data types returned from float queries starting with PHP 8.4 #15810

@janedbal

Description

@janedbal

Description

The following code:

<?php

$pdo = new PDO('pgsql:host=pgsql;dbname=foo', 'root', 'secret');
$pdo->exec('DROP TABLE IF EXISTS test');
$pdo->exec('CREATE TABLE test (col_float FLOAT)');
$pdo->exec('INSERT INTO test VALUES (0.125)');

$result = $pdo->query('SELECT col_float FROM test')->fetchColumn();

var_dump($result);

Resulted in this output:

float(0.125)

But I expected this output instead:

string(5) "0.125"

This behaviour changes in PHP 8.4 (prior this version, you always get string) and seems to affect all float results. This was detected by failing phpstan-doctrine tests where we infer data types returned from drivers.

I didnt find any relevant note about this behaviour change in UPGRADING notes, so this feels unintentional. I suspect #14035 might be the cause.

I can provide fully dockerized repository for reproduction if needed.

PHP Version

PHP 8.4.0beta4

Operating System

Debian 12 (bookworm)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions