Coder Social home page Coder Social logo

Comments (1)

kylekatarnls avatar kylekatarnls commented on July 24, 2024 6

Hello, they are both handled by the magic __call and the unit is normalized so to allow both with or without s.

In practice they are indeed just alias one for each other. And because the default value is 1, calling it with no parameters will add 1 unit.

But we recommend to use it semantically (to make the code unambiguous and easier to understand) following the rules below:

  • Don't pass any argument to addMonth(), addDay(), addSecond() etc.
  • Always pass 1 argument to addMonths($value), addDays($value), addSeconds($value) etc.

(the plural method is meant to pass either a value different than 1 or a dynamic value (variable, function call result, etc.)

I considered already to make the parameter mandatory for plural method and throw an exception when passing argument to the singular method, but this is a breaking change and it has a lot of indirect consequences that can make it hard for all the users to update (most people have carbon as a sub-dependency so they don't control easily which version they have, that's why we need to proceed breaking changes with parsimony).

As a first step (when stepping from 2.x to 3.x) the type has moved from PHPDoc to concrete type hint (previously it was practically possible to pass null or false.

For the documentation, here it aims to tell how to use in a way that is relevant and is guaranteed to work on the long run, calling ->addMonth(2) or ->addMonths() will likely trigger an deprecation notice, then an error in a later version, so I advise to consider following the documentation even if at the moment it's not enforced at runtime.

from carbon.

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.