Skip to content

Update ibm_db2.stub.php #32

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

Merged
merged 1 commit into from
Feb 23, 2023
Merged

Update ibm_db2.stub.php #32

merged 1 commit into from
Feb 23, 2023

Conversation

phansys
Copy link
Contributor

@phansys phansys commented Feb 20, 2023

  • Argument 2 for db2_autocommit() is optional, but not nullable;
  • Argument 1 in db2_stmt_errormsg(), db2_stmt_error(), db2_conn_errormsg() and db2_conn_error() was explicitly declared as nullable;
  • The resource type declaration was removed from argument 1 in db2_specialcolumns(), as is not available (see https://wiki.php.net/rfc/resource_typehint).

@phansys phansys marked this pull request as ready for review February 20, 2023 21:34
ibm_db2.stub.php Outdated
@@ -27,7 +27,7 @@ function db2_pconnect(string $database, ?string $username, ?string $password, ar
/**
* @param resource $connection
*/
function db2_autocommit($connection, ?int $value = null): int|bool {}
function db2_autocommit($connection, int $value = null): int|bool {}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function db2_autocommit($connection, int $value = null): int|bool {}
function db2_autocommit($connection, int $value): int|bool {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This parameter is optional. How do we make this explicit if we remove the default value?

* XXX: How do we represent optionals without defaults?

Copy link
Member

Choose a reason for hiding this comment

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

if this is not nullable, we can't set the default to null, can we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the only way in PHP to allow optional parameters is to defining default values for them. Generally, the default value used when the intention is to represent the absence of a value, is null.
See https://3v4l.org/2JIXi.

Copy link
Member

Choose a reason for hiding this comment

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

I get that, but as you can see (https://3v4l.org/utCc3), if you don't specify a value, the default will be NULL, which in turn would result in an error when called this way.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let me go through the stub again and check the other functions. I just wanted to make the function semantically correct for what is shown in the stub, because right now it is not.
According to the stub, one can send NULL, because NULL would be sent by default if no 2nd argument was passed. And this is just not true.

Maybe I have to take a step back and re-evaluate my understanding of the stub.

Copy link
Member

Choose a reason for hiding this comment

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

I'll also note that my translation from the old way of declaring functions to the stub might not be perfect. I tested against the test suite and user reports, but there's definitely the possibility I got some of the signatures wrong.

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'll also note that my translation from the old way of declaring functions to the stub might not be perfect. I tested against the test suite and user reports, but there's definitely the possibility I got some of the signatures wrong.

As far as I can see, there are no problems about the way that the signatures are represented regarding the PHP syntax.

One thing to mention: Even if the language interpreter allows this behavior near nullable arguments without notice, I think we SHOULD use the available syntax following this convention:

  1. Argument 1 MUST be passed, allowing int or null:
function test(?int $param) {};
  1. Argument 1 is optional, and allows int or null:
function test(?int $param = null) {};
  1. Argument 1 is optional, and allows only int (the case in db2_autocommit()):
function test(int $param = null) {};

Copy link
Member

@kocsismate kocsismate Feb 22, 2023

Choose a reason for hiding this comment

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

If an optional parameter doesn't have a valid default value then you can use the UNKNOWN pseudo default value. php-src has quite a few of such parameters (although most of them will be phased out if my RFC in progress will be accepted).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the help @kocsismate!
I've updated the PR with your suggestion.

@NattyNarwhal
Copy link
Member

Per php/php-src#8931 - should we be setting the version stuff in the stub?

@kocsismate
Copy link
Member

kocsismate commented Feb 22, 2023

Per php/php-src#8931 - should we be setting the version stuff in the stub?

@NattyNarwhal The default is PHP 7.0, so if you have a minimum PHP version requirement other than this then you should set the version.

Although unfortunately only PHP 7.0 and PHP 8.x is accepted... So I guess then you are not required to set it for now. It may come handy though for future reference if the requirements are bumped to 8.x+.

Copy link
Member

@NattyNarwhal NattyNarwhal left a comment

Choose a reason for hiding this comment

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

lgtm, though maybe we'd want to wait for helmut's suggested change for autocommit argument handling?

@phansys
Copy link
Contributor Author

phansys commented Feb 22, 2023

@NattyNarwhal, what do you think about this flow?

  1. Merge this PR in order to warranty the stubs are up to date and the headers are in sync with it;
  2. Merge [CI] Check that headers are up to date in the CI pipeline #35 to ensure any future change in the stub is up to date with the headers;
  3. Merge any other change, like the one proposed by @tessus.

@NattyNarwhal
Copy link
Member

That seems reasonable to me.

@NattyNarwhal NattyNarwhal merged commit 0af91df into php:master Feb 23, 2023
@phansys phansys deleted the stub branch February 23, 2023 16:26
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.

4 participants