Skip to content

run-tests: remove use of FILE_BINARY constant #5556

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 1 commit into from

Conversation

gerardroche
Copy link
Contributor

The FILE_BINARY (and FILE_TEXT) constants are not really valid or useful
constants. It looks like they were added in 5.2.7 and have "no effect,
and are only available for forward compatibility."

See: https://www.php.net/manual/en/filesystem.constants.php

The default value of the file_put_contents() flags parameter is 0 and
FILE_BINARY is set to 0, so removing it doesn't change functionality.

P.S. Maybe those constants should be deprecated or removed in 8.0.

The FILE_BINARY (and FILE_TEXT) constants are not really valid or useful
constants. It looks like they were added in 5.2.7 and have "no effect,
and are only available for forward compatibility."

See: https://www.php.net/manual/en/filesystem.constants.php

The default value of the file_put_contents() flags parameter is 0 and
FILE_BINARY is set to 0, so removing it doesn't change functionality.

P.S. Maybe those constants should be deprecated or removed in 8.0.
@cmb69
Copy link
Member

cmb69 commented May 12, 2020

Maybe those constants should be deprecated or removed in 8.0.

If we do this, we should not forget the t and b modes of fopen().

@php-pulls php-pulls closed this in 16f23cd May 12, 2020
@gerardroche gerardroche deleted the fix-file-binary branch May 12, 2020 16:50
@gerardroche
Copy link
Contributor Author

Maybe those constants should be deprecated or removed in 8.0.

If we do this, we should not forget the t and b modes of fopen().

The documentation has a lot of notes about the "t" and "b" modes of fopen():

Windows offers a text-mode translation flag ('t') which will transparently translate \n to \r\n when working with the file. In contrast, you can also use 'b' to force binary mode, which will not translate your data. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.

The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons. You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.

If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data, including broken image files and strange problems with \r\n characters.

Note:
For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().

Note:
Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead.

https://www.php.net/manual/en/function.fopen.php

Is any of that true? Or do "t" and "b" in fopen() mean the same as FILE_TEXT and FILE_BINARY constants which means they do nothing?

@cmb69
Copy link
Member

cmb69 commented May 12, 2020

Is any of that true?

That may depend on the wrapper, but for plain files it is.

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