Git Product home page Git Product logo

Comments (7)

stof avatar stof commented on July 17, 2024

Well, we simply cannot redefine the function to change its behavior when using APCu 4.x. PHP does not support replacing functions which are already defined.

from polyfill.

davidstrauss avatar davidstrauss commented on July 17, 2024

I'm not really asking for a replacement, more of an abstraction that spans both behaviors if you need to support both.

from polyfill.

stof avatar stof commented on July 17, 2024

Polyfills are not about providing an abstraction. An abstraction is not a polyfill anymore but a separate API (but nothing forbids you to build such abstraction separately).

from polyfill.

davidstrauss avatar davidstrauss commented on July 17, 2024

Polyfills are not about providing an abstraction.

I respectfully disagree. Polyfills are abstractions that just happen to provide the latest public API as the interface. Anything that hides underlying complexity or varying implementations is an abstraction.

In any case, a proper polyfill has to meet a few goals:

  1. Not implement APIs beyond those defined as the latest public APIs
  2. Provide fidelity between using the latest APIs and the polyfill
  3. Only provide its implementations where the underlying environment has gaps

You're declining to add novel functions/classes on the basis of the first and third goals, but this project currently fails to meet the second goal by having apcu_inc and apcu_dec with inconsistent behaviors. You have a quandary, as the APCu Polyfill is not a true polyfill if you don't satisfy all conditions. Since you cannot redefine functions in PHP, this project must choose which way it isn't quite a polyfill: either by adding its own, novel functions or not providing fidelity. Providing more functions is the more useful option.

Remy Sharp coined the term polyfill, and his own example of a polyfill explains its merit as not needing to feature-test or have branching behavior in code written on top of the polyfill:

Now with the polyfiller in place, as a developer I can rely on using the Web Storage API (for sessions) and not have to feature test in my code or fork to handle different situations.

Well, right now, I have to add a condition to handle the differing behavior of APCu 4.x, even though those functions are in the scope of APCu polyfill.

from polyfill.

davidstrauss avatar davidstrauss commented on July 17, 2024

Additionally, the definition and restrictions around polyfills were originally for Javascript, a language that allows redefinition of functions and other symbols. It therefore makes sense in Javascript to draw a hard line at defining new functions in a polyfill, but the capabilities of PHP are different.

from polyfill.

stof avatar stof commented on July 17, 2024

@davidstrauss you explicitly asked to provide an abstraction, which requires creating a new function not part of APCu. This is out of the scope of a polyfill.
We cannot replace the existing function in PHP (PHP does not support monkey-patching), so it means that the behavior you are asking us cannot be polyfilled.

Creating a new API on top of APCu to support this behavior on older versions is a different topic than polyfilling (though it has some similarity with it) and it should be done by a different package that symfony/polyfill.

from polyfill.

nicolas-grekas avatar nicolas-grekas commented on July 17, 2024

Closing as explained by @stof: there is no way to achieve this in PHP unfortunately.

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.