Skip to content

Redesign client_info and client_version in mysqli#6777

Closed
kamil-tekiela wants to merge 6 commits intophp:masterfrom
kamil-tekiela:fix-client-info
Closed

Redesign client_info and client_version in mysqli#6777
kamil-tekiela wants to merge 6 commits intophp:masterfrom
kamil-tekiela:fix-client-info

Conversation

@kamil-tekiela
Copy link
Copy Markdown
Member

There are two constants defined in the MySQL client API: client_info (string) and client_version (int). In MySQLnd these constants are pegged to the PHP version. In libmysql they represent the client library version used in compilation.

Until now, mysqli was exposing these constants in 4 different ways: mysqli_driver properties, mysqli properties, mysqli_get_client_info() function, and mysqli::get_client_info method. There was no method for client_version though.

The C MySQL library exposes these constants only in 2 ways to PHP: using a constant and using a function call. For this reason, I am proposing to unify the access method from mysqli to the same two options: a constant and a function call.

What is in this PR:

  • Deprecate passing connection object to mysqli_get_client_info()
  • Deprecate OO style mysqli::get_client_info method
  • Deprecate all 4 properties on mysqli and mysqli_driver class.
  • Add 4 new constants on mysqli and mysqli_driver class.

The goal is to remove mysqli_driver class at some point if possible, therefore the new constant is made redundant in both classes, but it is also possible to add it only to mysqli class.


final class mysqli_driver
{
/** @deprecated 8.1.0 */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, something is only deprecated after the new preferred usage is added. See #6754 for a similar example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that too. Generally, I agree that there should be first an alternate way and then deprecation, but in this case there already is an alternate way. If you think that this is a good idea then we can deprecate mysqli::get_client_info() now and deprecate properties in PHP 8.2. Not sure it will make much difference here. I just didn't want to add a fifth way of accessing these values without clearly marking which ones will be made obsolete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't have any strong preference, because your reasoning makes sense for me.

@nikic
Copy link
Copy Markdown
Member

nikic commented Mar 16, 2021

I feel like this makes for unnecessary churn for some functionality nobody really needs anyway. Can we keep this only at the first two bullet points? That is, keep the functions, keep the properties, drop the OO method and arg? That should arrive at a consistent interface.

@kamil-tekiela
Copy link
Copy Markdown
Member Author

@nikic The idea was to slowly fix all minor problems with mysqli. Having constants as read-only properties is certainly not desirable. I think that some people are using these constants in their code to check for the availability of certain functions. E.g. get_result().

I added a new commit that reverts all changes to the properties and the addition of new constants. But it makes no sense to me to keep them as object properties if they are never dependent on the object. And I definitely see no reason to have them as properties of mysqli_driver class.

Copy link
Copy Markdown
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add UPGRADING notes to the deprecated functionality section.

Co-authored-by: Nikita Popov <nikita.ppv@googlemail.com>

Fix P
@php-pulls php-pulls closed this in 7e9f6d2 Mar 17, 2021
jrfnl added a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Mar 9, 2022
…eter for `mysqli_get_client_info()`

> Calling `mysqli::get_client_info()` or `mysqli_get_client_info()` with the `mysqli` argument has been deprecated. Call `mysqli_get_client_info()` without any arguments to obtain the version information of the client library.

Includes unit tests.

Refs:
* https://github.com/php/php-src/blob/3a71fcf5caf042a4ce8a586a6b554fd70432e1e2/UPGRADING#L423-L426
* https://www.php.net/manual/en/migration81.deprecated.php#migration81.deprecated.mysqli
* php/php-src#6777
* php/php-src@7e9f6d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants