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

trigger_error instead of exceptions #104

Merged
merged 1 commit into from
Nov 1, 2018
Merged

trigger_error instead of exceptions #104

merged 1 commit into from
Nov 1, 2018

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Oct 30, 2018

Q A
Bug fix? yes
New feature? no
BC breaks? reverts BC break of #100
Deprecations? yes
Related tickets fixes #100
Documentation -
License MIT

What's in this PR?

Use trigger_error rather than throw exceptions

Why?

Consumers SHOULD are supposed to check isSeekable and only seek/rewind if that returns true, but it seems they don't all do that.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix

@@ -174,15 +179,17 @@ public function isSeekable()
*/
public function rewind()
{
throw new \RuntimeException('Cannot rewind a filtered stream');
@trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version');
$this->doRewind();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is rewind not possible with a filtered stream? is the filter expected to track what it already saw and would need resetting? otherwise it seems to me that only seek is problematic, but not rewind

Copy link
Member

Choose a reason for hiding this comment

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

It really depends on the implementation, but let's say you have a filtered stream that hash the body, rewinding the underlying body would then certainly change the hash produced

Filtered stream act as a pipe, you should never go back.

Also according to PSR7 rewind should raise an exception if the stream is not seekable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the clarification. so basically "you can't know" so you should not do it.

Copy link
Member

Choose a reason for hiding this comment

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

exactly

@@ -174,15 +179,17 @@ public function isSeekable()
*/
public function rewind()
{
throw new \RuntimeException('Cannot rewind a filtered stream');
@trigger_error('Filtered streams are not seekable. This method will start raising an exception in the next major version');
Copy link
Member

Choose a reason for hiding this comment

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

Maybe pass E_USER_DEPRECATED as the second argument to handle it as a normal deprecation?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO it's not a deprecation, but rather being nice to people using a buggy behavior

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Joel's reasoning, but raising it as a deprecation might help when using tools that detect deprecations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed from default (E_USER_NOTICE) to E_USER_DEPRECATED for better visibility

@dbu dbu merged commit b159ffe into master Nov 1, 2018
@dbu dbu deleted the avoid-bc-break branch November 1, 2018 09:32
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.

4 participants