Skip to content

strtok warns in case the string to split was not set. #10016

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

Conversation

devnexen
Copy link
Member

No description provided.

@cmb69
Copy link
Member

cmb69 commented Nov 29, 2022

strtok() is a terrible API, and I think this warning improves it a bit. I'm not sure about the wording of the message ("First call must set the string argument"); while this is usually correct, the adjustments to the existing tests are somewhat confusing. Maybe the problem is that the tests are written with for-loops instead of while-loops, but maybe we should change the message to something like "No string argument to tokenize set"?

@devnexen
Copy link
Member Author

strtok() is a terrible API, and I think this warning improves it a bit

It s likely more confusing for pure php devs I think, just trying to clarify a bit the "quirks" behind :)
I do not mind changing the wording if needs be, let s see what @kocsismate think.

@@ -1080,7 +1080,7 @@ PHP_FUNCTION(strtok)

if (!BG(strtok_string)) {
/* String to tokenize not set. */
// TODO: Should this warn?
php_error_docref(NULL, E_WARNING, "First call must set the string argument to tokenize with `%s`", ZSTR_VAL(tok));
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 fine with either error messages... as long as no string user input is exposed (ZSTR_VAL(tok)). :)

Just my 2c:
Both arguments must be provided when calling strtok() the first time

I'm really not sure which version is the best :)

Copy link
Member

Choose a reason for hiding this comment

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

Ok, the "first time" isn't really appropriate because the parameter must be provided whenever there is a new tokenization starting, so: Both arguments must be provided when starting tokenization

Copy link
Member Author

Choose a reason for hiding this comment

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

oky doky.

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.

Looks fine for me! Feel free to merge If @cmb69 is also satisfied with the error message :)

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Yeah, I like this error message! Thank you!

@devnexen devnexen closed this in 256a34e Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants