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.0 compatibility: function 'SetCharSet' #686

Closed
deining opened this issue Mar 8, 2021 · 3 comments
Closed

PHP 8.0 compatibility: function 'SetCharSet' #686

deining opened this issue Mar 8, 2021 · 3 comments
Assignees
Labels
bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues
Milestone

Comments

@deining
Copy link

deining commented Mar 8, 2021

Versions:

  • php 8.0.3
  • mysql Ver 15.1 Distrib 10.5.9-MariaDB
  • adodb 5.21.0

After upgrading to php 8, I encountered a fatal error when using my existing code base:

Stackstrace:

Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, bool given in /.../adodb/drivers/adodb-mysqli.inc.php:1206
Stack trace:
#0 /../adodb/drivers/adodb-mysqli.inc.php(1206): method_exists()
#1 /../myconnector.php(8):
ADODB_mysqli->SetCharSet()
thrown in /.../adodb/drivers/adodb-mysqli.inc.php on line 1206

My code is as simple as:

include('adodb/adodb.inc.php');
$db = ADONewConnection('mysqli');
$db->setCharset('utf-8');
...

If I comment out the line $db->setCharset('utf-8');, the error goes away.

Underlying reason: in PHP 8 method_exists now throws a Type Error if it encounters an unexpected value, which it didn't do previously.

Thanks for investigating the issue.

@peterdd
Copy link
Contributor

peterdd commented Mar 8, 2021

Maybe use

https://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:setconnectionparameter

before doing the real $db->connect()

instead of $db->setCharSet('utf-8');

I also stumbled over a similiar issue with PHP8, in my case it is get_class_methods() yet undocumented behavior change.

@dregad dregad added bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues labels Mar 8, 2021
@dregad dregad self-assigned this Mar 8, 2021
@dregad dregad added this to the v5.21.1 milestone Mar 8, 2021
@dregad
Copy link
Member

dregad commented Mar 8, 2021

Thanks for the bug report, will fix.

As a side note, $db->setCharset('utf-8'); will never work, because utf-8 is not a valid MySQL charset (see https://www.php.net/manual/en/mysqlinfo.concepts.charset.php), you should use utf8 or preferably utf8mb4 instead.

dregad added a commit that referenced this issue Mar 8, 2021
On mysqli, PHP 8 throws an 'Uncaught TypeError: method_exists():
Argument 1 ($object_or_class) must be of type object|string, bool
given'. Checking that _connectionID is set fixes the problem.

A similar issue was found and fixed with the postgres7 driver as well.

Note that fixing the legacy mysql driver is not necessary, as the driver
has been removed in PHP 7, and the error suppression operator should do
the job on PHP 5.

Fixes #686
@dregad dregad closed this as completed Mar 8, 2021
@mnewnham
Copy link
Contributor

mnewnham commented Mar 8, 2021

As another point, setCharSet is "sort of" deprecated. use setConnectionParameter instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mysqli MySQL and compatible drivers (MariaDB, etc) (Tier 1) PHP8 PHP 8 compatibility issues
Projects
None yet
Development

No branches or pull requests

4 participants