stream_copy_to_stream() treats $offset of 0 as "current position"
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Documentation does not mention that $offset of 0 keeps $from's position rather than copying from 0th offset.
<?php
$a = fopen('php://memory', 'r+');
$b = fopen('php://memory', 'r+');
fwrite($a, '0123456789');
fseek($a, 3);
stream_copy_to_stream($a, $b, 2, 0);
rewind($b);
echo stream_get_contents($b);
This code outputs 34 and not 01 as suggested by the documentation.
To me, this looks more like an implementation issue because $offset may depend on external factors such as user's input, and code most often doesn't expect the function's seeking behaviour to change if the input is zero or non-zero.
Related code (note the pos > 0 condition):
PHP_FUNCTION(stream_copy_to_stream)
{
// ...
if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) {
Contributor guide
No contributing guide indexed for this repository
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
Start with the stream_copy_to_stream() documentation and compare its $offset wording with ext/standard/streamsfuncs.c around the linked lines, especially the pos > 0 condition. Run the provided PHP example to confirm the behavior; done means the documentation accurately describes zero-offset behavior, or the issue is routed to the implementation if that behavior is unintended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100