Skip to content

Converting some warnings to errors in file.c #5007

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

Girgias
Copy link
Member

@Girgias Girgias commented Dec 11, 2019

Small intermediate step after #4991

Also removed some test which were basically testing erroneous values in fgetcsv, maybe I should do the same for fputcsv?

@Girgias Girgias force-pushed the file-func-warnings-to-errors branch 3 times, most recently from 7cfb206 to 3eb1bc7 Compare December 13, 2019 13:06
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.

Besides the one case which I commented on, this LGTM. Thanks!

php_error_docref(NULL, E_WARNING, "delimiter must be a character");
RETURN_FALSE;
zend_value_error("delimiter must be a character");
return;
} else if (delimiter_str_len > 1) {
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
Copy link
Member

Choose a reason for hiding this comment

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

I think it's important that we keep these pairs of warnings symmetrical. Either both should throw or neither.

Copy link
Member Author

Choose a reason for hiding this comment

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

Symmetrical with the SPL ones right? I'll do the changes at the same time borrowing parts from #4991

Copy link
Member

Choose a reason for hiding this comment

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

Symmetrical with the error above. I now realize though that in this case we throw a warning but still continue running the function, ugh. I think @cmb69's suggestion above to make this a single check (with BC break) may make the most sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok, want me to make that part of this PR or seperate one?

@@ -1831,8 +1831,8 @@ PHP_FUNCTION(fputcsv)
if (delimiter_str != NULL) {
/* Make sure that there is at least one character in string */
if (delimiter_str_len < 1) {
php_error_docref(NULL, E_WARNING, "delimiter must be a character");
RETURN_FALSE;
zend_value_error("delimiter must be a character");
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) This message is somewhat confusing, maybe "delimiter cannot be empty"?

Copy link
Member

Choose a reason for hiding this comment

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

That message would better reflect the check, but actually only the first char is ever used as delimiter; maybe it's worth introducing a pontetial BC break here, and check for delimiter_str_len == 1)? Same for enclosure a few lines below.

Copy link
Member

Choose a reason for hiding this comment

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

Another possibility would be to actually add support for multiple chars (effectively: Unicode support).

Copy link
Member Author

Choose a reason for hiding this comment

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

Another possibility would be to actually add support for multiple chars (effectively: Unicode support).

Tried to have a look, it seems that the whole fgetcsv and fputcsv sub-routines need to be rewritten. I don't mind either way to merge the checks or have them adapted to have multibyte support. But I feel this should rather be in a separate PR.

@Girgias Girgias force-pushed the file-func-warnings-to-errors branch from 3eb1bc7 to 9c9b4d9 Compare January 7, 2020 16:57
@Girgias
Copy link
Member Author

Girgias commented Jan 7, 2020

Azure pipeline failures are unrelated (sapi/fpm/tests/reload-uses-sigkill-as-last-measure.phpt)

@Girgias Girgias force-pushed the file-func-warnings-to-errors branch from 9c9b4d9 to 18f25a3 Compare January 20, 2020 03:02
@@ -3,8 +3,11 @@ Bug #71882 (Negative ftruncate() on php://memory exhausts memory)
--FILE--
<?php
$fd = fopen("php://memory", "w+");
var_dump(ftruncate($fd, -1));
try {
var_dump(ftruncate($fd, -1));
Copy link
Member

Choose a reason for hiding this comment

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

All the var_dump()s in try-catch blocks could be removed as it's sure that an exception is thrown before executing them. At least this is how I prefer to do it, so feel free to ignore. Otherwise, the PR looks good for me :)

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason I don't like removing them is if we remove the Error/Exception you need to go back up and add it to make sure that the behaviour is expected.

Also everything is just "standard". Moreover, this can be removed after the fact.

@Girgias
Copy link
Member Author

Girgias commented Jan 27, 2020

As it seems the only thing holding this up is the debate on how to handle the non symmetric warnings/errors in fputcsv(), which I'd rather address in a separate PR.

So if there are no further objections I'll merge this in a week.

@nikic
Copy link
Member

nikic commented Jan 27, 2020

Yes, this is fine to merge. fputcsv() etc changes are not really related.

@php-pulls php-pulls closed this in 9a76a2a Jan 27, 2020
@Girgias Girgias deleted the file-func-warnings-to-errors branch January 27, 2020 22:27
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.

4 participants