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

pgsql back-end resource handling broken on PHP 8.1 #37

Open
MarkMaldaba opened this issue Apr 1, 2024 · 7 comments
Open

pgsql back-end resource handling broken on PHP 8.1 #37

MarkMaldaba opened this issue Apr 1, 2024 · 7 comments
Labels

Comments

@MarkMaldaba
Copy link
Contributor

Since PHP 8.1, the postgres connection methods now return a PHP object rather than a resource.

From https://php.watch/versions/8.1/PgSQL-resource:

Prior to PHP 8.1, PostgreSQL extension returned and accepted database connections and results as resource objects. As part of PHP's resource to object migration, these resource types are migrated to class objects. All functions that returned a resource now return class objects instead, and all functions that accepted resource objects now accept the new class object, making this migration opaque with only the caveat being how a resource object is validated and closed.

In PEAR::DB, the DB_pgsql class is implemented on the assumption that the returned result is a PHP resource reference. In particular, the implementation type-casts the result to an integer which is used as an array index, which is no longer possible with the object implementation. In addition, there are checks using is_resource() which will fail on PHP 8, as this function only returns true for the resource implementation.

The class needs to be updated to handle both implementations, in order to support older PHP versions as well as continuing to run on PHP >= 8.1.

@schengawegga schengawegga added this to the Version 1.12.2 milestone Apr 2, 2024
@schengawegga
Copy link
Collaborator

@MarkMaldaba Thank you. I´ll have a look at it.

@rossnick
Copy link

Any news on this ? we just hit this issue and rather keep pear::db than rewrite code that uses it for the moment.

@tmitanitky
Copy link

Any news on this ? we just hit this issue and rather keep pear::db than rewrite code that uses it for the moment.

I'm just a user and got a workaround for this problem. It is to replace
(int)$result to spl_object_id($result) or spl_object_hash($result) in pear\DB\pgsql.php.

@schengawegga
Copy link
Collaborator

I´m sorry, but i´m very busy at the moment.
@tmitanitky Can you provide a pull-request, please?

@tmitanitky
Copy link

Sure. I made a PR. Please review it when you are good and ready. Thanks.

@tmitanitky
Copy link

Sorry, I found some mistakes. I closed the PR and will try it again.

@rossnick
Copy link

@tmitanitky I was wondering what mistakes did you found that led you to remove your PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants