Skip to content

feat(stubs): pgsql extension stub with the PGSQL_* constants - #14637

Merged
orklah merged 1 commit into
vimeo:masterfrom
jirkace:feat/9906-pgsql-stub
Nov 23, 2026
Merged

orklah merged 1 commit into
vimeo:masterfrom
jirkace:feat/9906-pgsql-stub

Conversation

@jirkace

@jirkace jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Without the pgsql extension loaded in the PHP running Psalm, every PGSQL_* constant is an UndefinedConstant, and pgsql can't be enabled in <enableExtensions>.

Before

<?php
function f(string $dsn): ?string {
    $connection = pg_connect($dsn, PGSQL_CONNECT_FORCE_NEW); // UndefinedConstant
    // ...
}

After

    $connection = pg_connect($dsn, PGSQL_CONNECT_FORCE_NEW); // no issue

The new stubs/extensions/pgsql.phpstub is enabled by ext-pgsql in composer.json or <extension name="pgsql"/>.

Fixes #9906

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • New extension stub stubs/extensions/pgsql.phpstub with the PGSQL_* constants, taken from PHP 8.4.28 with ext-pgsql (libpq 17) via get_defined_constants(true)['pgsql']. PGSQL_LIBPQ_VERSION and PGSQL_LIBPQ_VERSION_STR depend on libpq, so they are declared as non-empty-string instead of a literal.
  • pgsql is accepted in <enableExtensions> / <disableExtensions> (config.xsd, Config::$php_extensions), and ext-pgsql in composer.json now enables the stub.
  • The constants added in PHP 8.3 (PGSQL_SHOW_CONTEXT_*, PGSQL_TRACE_*) and 8.4 (PGSQL_TUPLES_CHUNK) are not version-gated (extension stubs have no gating for define()), so they are known for every analysed PHP version.
  • The pg_* functions and the PgSql\* classes come from the call map / versioned stubs as before.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 93.7 $\color{gray}{\textsf{+0.5\%}}$ 25 691 52 996 682
✅ symfony 3 596 259.3 $\color{gray}{\textsf{+1.1\%}}$ 50 610 98 403 1 528
✅ doctrine-orm 380 16.8 $\color{gray}{\textsf{-1.9\%}}$ 3 481 6 143 0
✅ psl 617 21.4 $\color{gray}{\textsf{-0.2\%}}$ 1 375 5 615 1
✅ phpunit 455 20.7 $\color{gray}{\textsf{-2.3\%}}$ 1 731 3 410 18
✅ php-parser 226 14.1 $\color{gray}{\textsf{-5.4\%}}$ 17 154 21 245 0
✅ tempest 895 39.6 $\color{gray}{\textsf{+4.7\%}}$ 5 047 10 528 252
✅ amphp-amp 45 1.1 $\color{gray}{\textsf{-0.9\%}}$ 29 49 0
✅ webmozarts-assert 272 3.5 $\color{gray}{\textsf{-0.3\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.2 155 434 2
✅ monolog 135 4.3 $\color{gray}{\textsf{+1.2\%}}$ 913 2 479 10
✅ drupal 4 839 145.9 $\color{gray}{\textsf{+1.7\%}}$ 97 591 169 293 583
Total 13 273 621.7 $\color{gray}{\textsf{+1.0\%}}$ 204 354 373 315 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head 49a6209 · base 9028ade (merge-base) · workflow run

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 23, 2026
@orklah

orklah commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jirkace!

@orklah
orklah merged commit 2e300e5 into vimeo:master Nov 23, 2026
160 of 164 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Psalm does not know about PGSQL_* constants

2 participants