-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-8273: SplFileObject: key() returns wrong value
- Loading branch information
Showing
4 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--TEST-- | ||
SplFileObject verify interactions between seeking, getting the key and fgets | ||
--FILE-- | ||
<?php | ||
|
||
$file = new SplTempFileObject(); | ||
|
||
for ($i = 0; $i < 100; $i++) { | ||
$file->fwrite("Foo $i\n"); | ||
} | ||
|
||
$file->seek(50); | ||
|
||
var_dump( | ||
['line' => $file->key(), 'contents' => trim($file->fgets())], | ||
['line' => $file->key(), 'contents' => trim($file->fgets())], | ||
['line' => $file->key(), 'contents' => trim($file->fgets())], | ||
); | ||
|
||
?> | ||
--EXPECT-- | ||
array(2) { | ||
["line"]=> | ||
int(50) | ||
["contents"]=> | ||
string(6) "Foo 50" | ||
} | ||
array(2) { | ||
["line"]=> | ||
int(51) | ||
["contents"]=> | ||
string(6) "Foo 51" | ||
} | ||
array(2) { | ||
["line"]=> | ||
int(52) | ||
["contents"]=> | ||
string(6) "Foo 52" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
GH-8273 (SplFileObject: key() returns wrong value) | ||
--FILE-- | ||
<?php | ||
|
||
$file = new SplTempFileObject(); | ||
|
||
// write to file | ||
for ($i = 0; $i < 5; $i++) { | ||
$file->fwrite("line {$i}" . PHP_EOL); | ||
} | ||
|
||
// read from file | ||
$file->rewind(); | ||
while ($file->valid()) { | ||
echo $file->key(), ': ', $file->fgets(); | ||
} | ||
?> | ||
--EXPECT-- | ||
0: line 0 | ||
1: line 1 | ||
2: line 2 | ||
3: line 3 | ||
4: line 4 |
660ef91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Girgias I just got a merge conflict when merging from PHP-8.0. Seems like you merged two different versions (separate commits) and forgot to merge the PHP-8.0 before that which is necessary to keep merge up working cleanly. I used PHP-8.1 version here but please double check if it's all good.
660ef91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I did the merge correctly >_> by merging 8.0 into 8.1 and then 8.1 into master, but must have made a mistake (or perhaps the NEWS file?), thanks for letting me know however I'll try to make sure the merges are clean
660ef91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply.
It was because you created another commit somehow: 6186ecd without merging it up. But if it's all looking good, then it's fine.