Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calling pg_fetch_result() With 2 Arguments Is Deprecated

pg_fetch_result() accepted two call shapes: a 3-argument form giving the row and field explicitly, and a 2-argument form that omitted the row and implicitly read from an internal, auto-advancing row cursor instead. Mixing an explicit-row API with a stateful, cursor-based one in the same overloaded function made the behavior harder to predict. Until PHP 8.4, calling the 2-argument form was completely silent. In PHP 8.4, it emits a deprecation notice, in favor of always passing 3 arguments and using null for $row when the old auto-advancing behavior is wanted; the underlying validation of the other arguments (here, that $result is a real PgSql\Result) is unaffected.

PHP code

<?php

try {
    var_dump(pg_fetch_result('not-a-resource', 'field'));
} catch (\Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

Before

TypeError: pg_fetch_result(): Argument #1 ($result) must be of type PgSql\Result, string given

After

PHP Deprecated:  Calling pg_fetch_result() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in /codes/pgFetchResultTwoArgsDeprecated.php on line 4

Deprecated: Calling pg_fetch_result() with 2 arguments is deprecated, use the 3-parameter signature with a null $row parameter instead in /codes/pgFetchResultTwoArgsDeprecated.php on line 4
TypeError: pg_fetch_result(): Argument #1 ($result) must be of type PgSql\Result, string given

PHP version change

This behavior was deprecated in 8.4.

This behavior changed in .

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat