Skip to content

Add ext/mysqli stubs #4913

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

Closed
wants to merge 1 commit into from
Closed

Add ext/mysqli stubs #4913

wants to merge 1 commit into from

Conversation

tvlooy
Copy link
Contributor

@tvlooy tvlooy commented Nov 15, 2019

No description provided.

@carusogabriel
Copy link
Contributor

@tvlooy Thanks for your contribution man. Could you please rebase with master?

@tvlooy tvlooy force-pushed the 106522_mysqli branch 2 times, most recently from 27d252d to 45e91eb Compare November 15, 2019 14:57
@tvlooy tvlooy force-pushed the 106522_mysqli branch 2 times, most recently from 88073d9 to f04f03a Compare November 15, 2019 15:48
@tvlooy tvlooy changed the title Add ext/mysqli stubs WIP Add ext/mysqli stubs Nov 15, 2019
@tvlooy tvlooy changed the title WIP Add ext/mysqli stubs WIP: Add ext/mysqli stubs Nov 15, 2019
@tvlooy tvlooy changed the title WIP: Add ext/mysqli stubs Add ext/mysqli stubs Nov 24, 2019
Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

@tvlooy I could only review very few functions/methods.

*
* @return bool
*/
public function commit(?int $flags = 0, ?string $name = '');
Copy link
Member

Choose a reason for hiding this comment

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

these are not nullable parameters (there is no ! in the ZPP). That said, the $name parameter's default value should be UNKNOWN AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how can I know that it should be UNKNOWN?

Copy link
Member

Choose a reason for hiding this comment

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

There is some information written about it by Nikita: https://externals.io/message/106522 (the whole thread is interesting, but you should search for "UNKNOWN"). :)

@kocsismate
Copy link
Member

@tvlooy Do you plan to continue working on these stubs in the foreseeable future? If so, I'll try to help you by reviewing the code, otherwise I can also continue it.

@tvlooy
Copy link
Contributor Author

tvlooy commented Dec 22, 2019

@tvlooy Do you plan to continue working on these stubs in the foreseeable future? If so, I'll try to help you by reviewing the code, otherwise I can also continue it.

I changed the docblocks like you asked. I rebased and sqashed commits. Tests still pass.

I might have underestimated this a bit. I have trouble figuring out the return types and need help with it. Maybe it is better if I hand it over to you.

@kocsismate
Copy link
Member

kocsismate commented Dec 22, 2019

@tvlooy You feel right, the return types are usually (much) more difficult to find out than parameter types.

What you have to look for in most cases is RETVAL_* (e.g. RETVAL_BOOL) and RETURN_* (e.g. RETURN_BOOL) macros, or sometimes the return_value variable itself. The first ones set the return type of the function (by setting the value of the return_value variable), the second ones additionally return. In order to determine the exact return type of a function, you have to take the return value of all branches into account (and that's where union types come into play).

There are lots of functions in mysqli, so I can understand that you feel it's too much. I'd suggest you to make smaller changes next time (by splitting the work) so it's easier for you when you try to learn how all these things work, and it's easier for the reviewers as well. 😎

My plan is to first work on the SPL (probably after the holidays) so that you have some extra time to decide if you want to proceed with the work.

@tvlooy
Copy link
Contributor Author

tvlooy commented Dec 23, 2019

Okay. Then I will do a full review this week.

Copy link
Contributor Author

@tvlooy tvlooy left a comment

Choose a reason for hiding this comment

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

@kocsismate I'm curious how the return_value actually works. ps: I'm reviewing but not done yet. Learning a lot. Thank you for your patience 😊

@cmb69
Copy link
Member

cmb69 commented Jan 3, 2020

@kocsismate
Copy link
Member

@tvlooy Take your time, I have plenty other stuffs to do :) You could have a look at this too https://github.com/php/php-src/blob/master/docs/parameter-parsing-api.md (if you haven't seen it yet), it also helped me a lot.

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 13, 2020

@kocsismate

questions about close():

  • now that the null is gone, should this return true or bool in the signature?
  • if it will only return true, why not just make that return nothing and change the method?

question about character_set_name():

  • what does this return when cs_name is false?

@nikic
Copy link
Member

nikic commented Feb 13, 2020

* now that the null is gone, should this return true or bool in the signature?

For now, bool. We currently don't support true as a type, so these are typed as bool.

* if it will only return true, why not just make that return nothing and change the method?

In principle yes, but there's backwards compatibility considerations, so if we do this, it should be as a separate change.

@kocsismate
Copy link
Member

what does this return when cs_name is false?

By default, the return value is null.

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 13, 2020

what does this return when cs_name is false?

By default, the return value is null.

I will change the signature for character_set_name() and also for get_client_info(), get_server_info() which seems to have the same case

@nikic
Copy link
Member

nikic commented Feb 15, 2020

What's the state of this PR, is it ready for review?

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 15, 2020

What's the state of this PR, is it ready for review?

@nikic @kocsismate the PR is updated and ready for review.
Do check if __construct() of mysqli_warning, mysqli_result and mysqli_stmt can be improved.

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

Really nice job! I could only find a few issues so far (I reached to mysqli_warning).

class mysqli_warning
{
/**
* mysqli_link|mysqli_stmt $mysqli_link
Copy link
Member

@kocsismate kocsismate Feb 17, 2020

Choose a reason for hiding this comment

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

it's invalid PHPDoc (+ there is no parameter added in the param list), but as no exception is thrown in case a wrong object is provided, you should fallback to the object type declaration

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed docblock but didn't change method signature (things break if I do). What should be in the signature?

@nikic
Copy link
Member

nikic commented Feb 18, 2020

FYI I killed the mysqli reflection tests in 541f8b7. They are useless and just cause extra work.

*
* @return object|false
*/
public function __construct();
Copy link
Member

Choose a reason for hiding this comment

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

what kind of errors are thrown when you add the parameters in the definition? 🤔

Copy link
Contributor Author

@tvlooy tvlooy Feb 19, 2020

Choose a reason for hiding this comment

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

changed and it works with object for mysqli_result::__construct and mysqli_warning::__construct()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get a "Fatal error: Arginfo / zpp mismatch during call of mysqli_stmt::__construct() in Unknown on line 0" when I change the signature to (object $mysqli_link, string $statement)

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 19, 2020

FYI I killed the mysqli reflection tests in 541f8b7. They are useless and just cause extra work.

rebased. Thanks for zapping the files

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

That's all the issues I could find. Mostly just a category issue with nullable return types. Huge work, @tvlooy!

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 22, 2020

That's all the issues I could find. Mostly just a category issue with nullable return types. Huge work, @tvlooy!

I should have spotted those return types. Thanks for the review!

@kocsismate
Copy link
Member

kocsismate commented Feb 22, 2020

@tvlooy There is one failing test left related to mysqli_insert_id(). The issue is that the MYSQLI_RETURN_LONG_INT() macro can return string as well, so please double check the return type everywhere where it is used.

@tvlooy
Copy link
Contributor Author

tvlooy commented Feb 22, 2020

MYSQLI_RETURN_LONG_INT

Fixed! And rebased

@kocsismate
Copy link
Member

kocsismate commented Feb 24, 2020

The PR looks good to me but I think Nikita should have a look at it too before merging. :)

@php-pulls php-pulls closed this in fabe6a3 Feb 25, 2020
@nikic
Copy link
Member

nikic commented Feb 25, 2020

I didn't comprehensively review this again, just added the missing mysqli_stmt::__construct signature and merged...

Thanks for your work on this!

@tvlooy tvlooy deleted the 106522_mysqli branch February 27, 2020 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants