Giter Club home page Giter Club logo

Comments (4)

Tobion avatar Tobion commented on May 1, 2024

I agree that there is a problem. \Psr\Http\Message\StreamInterface::read should return a string or throw an exception. Both are not done because it causes a warning and returns false because fread returns false in this case. There are two solutions:

  1. ignore length of 0 an return '' as you suggested,
  2. transform the warning to an exception, so length of 0 will still fail.

Considering the use-case you gave above makes sense I tend to favor solution 1) because reading 0 bytes seems useless but is not an error.
I also checked other Stream APIs like the underlying C API, and nodejs, and Java, and Go. None of them throw an exception when reading with length of 0.

from psr7.

zyfran avatar zyfran commented on May 1, 2024

Thank you @Tobion
Do I need to create merge request?

from psr7.

Tobion avatar Tobion commented on May 1, 2024

Would be nice if you create a PR. When length === 0, return ''. And also check if fread returns false and throw an exception then. So a negative length will still fail.

from psr7.

zyfran avatar zyfran commented on May 1, 2024

@Tobion Thank you

from psr7.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.