GithubHelp home page GithubHelp logo

Comments (4)

stof avatar stof commented on September 3, 2024

PHP 8.0 also introduces an internal mechanism that automatically adds the string return type to __toString because this magic method was already strict in earlier versions.
This is why the Stringable polyfill has been implemented without an explicit return type to allow writing code compatible with more PHP versions.

from polyfill.

stof avatar stof commented on September 3, 2024

Note that the Stringable class from the polyfill is only loaded on PHP 7.x and older. On PHP 8.0+, the native implementation is the one being used anyway.

from polyfill.

lkrms avatar lkrms commented on September 3, 2024

PHP 8.0 also introduces an internal mechanism that automatically adds the string return type to __toString because this magic method was already strict in earlier versions. This is why the Stringable polyfill has been implemented without an explicit return type to allow writing code compatible with more PHP versions.

Interesting. This behaviour isn't covered in the documentation for Stringable, but it checks out. Yay for undocumented internal mechanisms 🎉 /s

Note that the Stringable class from the polyfill is only loaded on PHP 7.x and older. On PHP 8.0+, the native implementation is the one being used anyway.

Yes, sorry, I should have mentioned the issue only surfaces on PHP 7.x.

from polyfill.

derrabus avatar derrabus commented on September 3, 2024

PHP 8.0 introduced Stringable::__toString() with a return type of string that's enforced at runtime

No, it is not: https://3v4l.org/UpafS

This causes tests and static analysis of Stringable implementations with no __toString() return type to succeed

Which is exactly how that interface behaves on PHP 8. Our polyfill must not be more strict than the real implementation. And even if we did, your static analysis issues would resurface once you upgrade to PHP 8.

Your static analysis issue is 100% home made.

from polyfill.

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.