Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 pg_query() stubs issue #7138

Closed
zbenc opened this issue Apr 27, 2022 · 2 comments
Closed

PHP 8.1 pg_query() stubs issue #7138

zbenc opened this issue Apr 27, 2022 · 2 comments
Labels
Milestone

Comments

@zbenc
Copy link

zbenc commented Apr 27, 2022

Bug report

PHPStan (1.6.2) incorrectly reports errors for pg_query() for PHP 8.1:

It does not seam to be aware that pg_query() expects a PgSql\Connection object as the first parameter and returns a PgSql\Result object as of PHP 8.1. I have checked the PHP 8 stubs at https://github.com/phpstan/php-8-stubs/blob/main/stubs/ext/pgsql/pg_query.php but cannot spot an issue there as those signatures include the correct PHP 8.1 derivative.

Code snippet that reproduces the problem

function test(): \PgSql\Result|false {
  return \pg_query(\pg_connect(''), '');
}

https://phpstan.org/r/e6aba2b0-e06c-4e46-835a-a1b1fbe294d3

Expected output

No error messages

@zbenc zbenc changed the title PHP 8.1 pg_query stubs issue PHP 8.1 pg_query() stubs issue Apr 27, 2022
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 2, 2022
@phpstan-bot
Copy link
Contributor

@zbenc After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.1 (3 errors)
+PHP 8.1 (1 error)
 ==========
 
-3: Function test() never returns PgSql\Result so it can be removed from the return type.
-4: Function test() should return PgSql\Result|false but returns resource|false.
-4: Parameter #1 $connection of function pg_query expects resource, PgSql\Connection|false given.
+4: Parameter #1 $connection of function pg_query expects PgSql\Connection|string, PgSql\Connection|false given.
 
 PHP 8.0 (4 errors)
 ==========
Full report

PHP 8.1 (1 error)

Line Error
4 `Parameter #1 $connection of function pg_query expects PgSql\Connection

PHP 8.0 (4 errors)

Line Error
3 Function test() has invalid return type PgSql\Result.
3 Function test() never returns PgSql\Result so it can be removed from the return type.
4 `Function test() should return PgSql\Result
4 `Parameter #1 $connection of function pg_query expects resource, resource

PHP 7.1 – 7.4 (5 errors)

Line Error
3 Function test() has invalid return type PgSql\Result.
3 Function test() never returns PgSql\Result so it can be removed from the return type.
3 Function test() uses native union types but they're supported only on PHP 8.0 and later.
4 `Function test() should return PgSql\Result
4 `Parameter #1 $connection of function pg_query expects resource, resource

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants