FILE_SKIP_EMPTY_LINES only works with FILE_IGNORE_NEW_LINES
Open
Nobody has claimed this yet.
Bug
Extension: standard
Status: Verified
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code (https://3v4l.org/Ys4MU):
<?php
$filename = tempnam('/tmp', 'testing-');
file_put_contents($filename, "First\n\nSecond\n");
$lines = file($filename, FILE_SKIP_EMPTY_LINES);
echo "Just FILE_SKIP_EMPTY_LINES:\n";
var_dump( ...$lines );
echo "Also FILE_IGNORE_NEW_LINES:\n";
$lines2 = file($filename, FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES);
var_dump( ...$lines2 );
unlink($filename);
Resulted in this output:
Just FILE_SKIP_EMPTY_LINES:
string(6) "First
"
string(1) "
"
string(7) "Second
"
Also FILE_IGNORE_NEW_LINES:
string(5) "First"
string(6) "Second"
But I expected this output instead:
Just FILE_SKIP_EMPTY_LINES:
string(6) "First
"
string(7) "Second
"
Also FILE_IGNORE_NEW_LINES:
string(5) "First"
string(6) "Second"
PHP Version
8.3+
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided reproduction first to confirm the behavior of file() with FILE_SKIP_EMPTY_LINES. Then trace the PHP implementation handling FILE_SKIP_EMPTY_LINES with and without FILE_IGNORE_NEW_LINES. Done means empty lines are skipped in both cases while the non-empty line endings retain the demonstrated behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100