-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
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 {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function db2_autocommit($connection, int $value = null): int|bool {} | |
function db2_autocommit($connection, int $value): int|bool {} |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Argument 1 MUST be passed, allowing
int
ornull
:
function test(?int $param) {};
- Argument 1 is optional, and allows
int
ornull
:
function test(?int $param = null) {};
- Argument 1 is optional, and allows only
int
(the case indb2_autocommit()
):
function test(int $param = null) {};
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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+. |
There was a problem hiding this 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?
@NattyNarwhal, what do you think about this flow?
|
That seems reasonable to me. |
db2_autocommit()
is optional, but not nullable;db2_stmt_errormsg()
,db2_stmt_error()
,db2_conn_errormsg()
anddb2_conn_error()
was explicitly declared as nullable;resource
type declaration was removed from argument 1 indb2_specialcolumns()
, as is not available (see https://wiki.php.net/rfc/resource_typehint).