Skip to content
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

creating a stream from string has unexpected behaviour #177

Merged
merged 1 commit into from
May 10, 2021
Merged

creating a stream from string has unexpected behaviour #177

merged 1 commit into from
May 10, 2021

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Apr 22, 2021

when creating a stream from a string, the resource should be rewinded.

fix #176

public function testBuildFromString()
{
$stream = Stream::create('data');
$this->assertEquals('data', $stream->getContents());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

RE the discussion in #176, i find it highly unexpected that this does not work.

@Nyholm Nyholm mentioned this pull request May 10, 2021
@Nyholm
Copy link
Owner

Nyholm commented May 10, 2021

Thank you.

See #176 for discussion.

@Nyholm Nyholm merged commit d937173 into Nyholm:master May 10, 2021
@dbu dbu deleted the fix-string-stream branch May 11, 2021 06:40
@dbu
Copy link
Contributor Author

dbu commented May 11, 2021

thanks!

@Zegnat
Copy link
Collaborator

Zegnat commented May 11, 2021

@Nyholm with this merged, should the next release be a major version bump per semver? Or do you want to run this as a bug fix only? It has the potential to break people’s implementations if they were building on top of what was previously a stable API from this library.

@dbu
Copy link
Contributor Author

dbu commented May 11, 2021

the only scenario for this to fail is when you create a stream with a non-empty string and rely on the stream being empty because it is not rewinded. is there any use case where this could matter?

maybe theoretically if you create the stream with a string but then want to append to the stream you now overwrite the string? no idea what people do and if this could happen, but maybe it can?

@Nyholm
Copy link
Owner

Nyholm commented May 11, 2021

I think the same principal should apply.

You should never assume where the read pointer is. That is not part of any BC promise.

previously a stable API from this library.

That is true, but I am arguing that this never was a part of the API. The correct way is to always place your pointer after you read/write from a stream.

But we could maybe be more explicit about this by releasing a minor version instead and with a clear note in the changelog. What do you think?

@Zegnat
Copy link
Collaborator

Zegnat commented May 11, 2021

You should never assume where the read pointer is. That is not part of any BC promise.

My argument would be that Stream::create() is part of the nyholm/psr7 API, even if not defined by PSR. The output of Stream::create('Hello') can no longer be chained with ->write(' world!') without the result being different. This to me means we have broken the BC promise with this PR.

If only the PSR methods are seen as included in the promise (or in the “public API” as semver says), it can easily be argued that the promise specifically does not mention the pointer. This would just be a patch or minor release to bring us inline with another part of the ecosystem. But if our own static factory methods are part of the promise my hardliner stance would be that a major version increase is required per strict semver.

(Alternatively both can be true, and one can argue the library never stated it was following strict semver.)

I am not sure I have a strong opinion about this, if we accept that we change the library to match the ecosystem we can just change it, but I know some people might have higher expectancies of semver.

@Nyholm
Copy link
Owner

Nyholm commented May 11, 2021

My argument would be that Stream::create() is part of the nyholm/psr7 API, even if not defined by PSR

True!

The output of Stream::create('Hello') can no longer be chained with ->write(' world!') without the result being different. This to me means we have broken the BC promise with this PR.

Hm... Im not 100% convinced my point is valid. But we never specified this behaviour and it was untested..

I do think we should follow semver and I do think we should avoid doing a new major release.

Currently we annoy the people that expect the stream to be rewinded, if we release this patch, we will annoy all other people... Hm..

@Nyholm Nyholm mentioned this pull request May 21, 2021
Nyholm added a commit that referenced this pull request Jun 19, 2021
@Nyholm Nyholm mentioned this pull request Jun 19, 2021
Nyholm added a commit that referenced this pull request Jul 2, 2021
* Revert #177

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants