Skip to content

Move a few custom type checks to ZPP #6034

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 4 commits into from

Conversation

kocsismate
Copy link
Member

No description provided.

@kocsismate kocsismate changed the title Add more accurate type info for stubs again Move a few custom type checks to ZPP Aug 22, 2020
@kocsismate kocsismate force-pushed the more-accurate-types2 branch 2 times, most recently from 735e36d to ed8e8d8 Compare August 22, 2020 23:01
@kocsismate kocsismate force-pushed the more-accurate-types2 branch from ed8e8d8 to edede27 Compare August 22, 2020 23:11
Comment on lines -1739 to +1740
zend_string *field_str;
zend_string *field_str, *pv_field_str;
zend_long pv_field_long;
Copy link
Contributor

@carusogabriel carusogabriel Aug 22, 2020

Choose a reason for hiding this comment

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

Quick question: moving from zvals to zend_(string|int|etc..) types, are they cheaper?

Also, is that a good practice to follow?

Copy link
Member Author

Choose a reason for hiding this comment

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

@carusogabriel I don't think they are noticably cheaper. The real benefit is being able to accept arguments whose type is validated according to the standard semantics, rather than in a custom way.

@kocsismate kocsismate force-pushed the more-accurate-types2 branch 3 times, most recently from d7e055e to fc60c36 Compare August 23, 2020 08:24
@kocsismate kocsismate force-pushed the more-accurate-types2 branch 3 times, most recently from 16d3169 to 22abceb Compare August 25, 2020 08:49
}
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
} else {
ret = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit unsure about this one. If we consider a call like mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, '100'), this was previously valid and the '100' was interpreted as 100. Now it will throw instead. That is, it's now necessary to match the type of the option, rather than the option forcing the type of the value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's a valid critique against the (former) implementation. Now, I've just pushed a change which tries to address this by trying to convert the type to the expected one if necessary. I like this solution, but I'm curious whether you see any problem with this approach.

Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of this. This has made the implementation more complicated than it was before.

I think it is better to keep this as a mixed argument. The fact that only int|string is accepted is rather incidential imho (e.g. there's no reason why in the future an option using float or bool value couldn't be added).

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted all these changes (from mysqli and xml both), but stayed with the string|int PHPDoc type hints.

@kocsismate kocsismate force-pushed the more-accurate-types2 branch from 22abceb to 0126355 Compare August 27, 2020 09:12
@kocsismate kocsismate force-pushed the more-accurate-types2 branch 2 times, most recently from 9408fe8 to 7a26727 Compare September 1, 2020 06:33

if (str_headers) {
tmp_headers = zend_string_init(ZSTR_VAL(str_headers), ZSTR_LEN(str_headers), 0);
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));
Copy link
Member

Choose a reason for hiding this comment

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

Drive-by note: I think the MAIL_ASCIIZ_CHECK_MBSTRING calls above are corrupting the argument strings :(

}
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
} else {
ret = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Not a fan of this. This has made the implementation more complicated than it was before.

I think it is better to keep this as a mixed argument. The fact that only int|string is accepted is rather incidential imho (e.g. there's no reason why in the future an option using float or bool value couldn't be added).

@kocsismate kocsismate force-pushed the more-accurate-types2 branch 4 times, most recently from 44a5c7a to 05ba96f Compare September 1, 2020 15:27
@php-pulls php-pulls closed this in 3e800e9 Sep 2, 2020
@kocsismate kocsismate deleted the more-accurate-types2 branch September 2, 2020 09:14
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