Giter Site home page Giter Site logo

Warning: Cannot bind an instance to a static closure in vendor/nesbot/carbon/src/Carbon/Traits/Date.php on line 2413 about business-day HOT 12 CLOSED

kylekatarnls avatar kylekatarnls commented on June 29, 2024
Warning: Cannot bind an instance to a static closure in vendor/nesbot/carbon/src/Carbon/Traits/Date.php on line 2413

from business-day.

Comments (12)

kylekatarnls avatar kylekatarnls commented on June 29, 2024

Please provide your config (the code with BusinessDay::enable(...) and your Carbon version so I can try to reproduce.

from business-day.

mpoma avatar mpoma commented on June 29, 2024

mi carbon.php is a customized file,with not standart region, laravel 8.25, "nesbot/carbon", "version": "2.44.0",

<?php 
return [
    'holidays' => [
        'region' => 'raps-national',
        'with' => [
            'new-year'  => '01-01',
            'easter-48'  => '= easter -48',
            'easter-47'  => '= easter -47',
            'day-of-remembrance-for-truth-and-justice'   => '03-24',
            'bridge-day'  => '= 03-24 if Tuesday then previous Monday and if Thursday then next Friday',
            'saint-thursday'    => '= easter -3',
            'saint-friday'  => '= easter -2',
            'day-of-the-veterans-and-the-fallen-of-malvinas-war'        => '04-02',
            'substitutes-day-of-the-veterans'  => '= 04-02 if Tuesday then previous Monday and if Thursday then next Friday',
            'labor-day' => '05-01',
            'substitutes-labor-day' => '= 05-01 if Tuesday then previous Monday and if Thursday then next Friday',
            'day-of-the-first-national-government'   => '05-25',
            'substitutes-may-revolution'  => '= 05-25 if Tuesday then previous Monday and if Thursday then next Friday',
            'guemes-day'   => '= 06-17 if Tuesday then previous Monday and if Wednesday,Thursday,Friday,Saturday,Sunday then next Monday',
            'national-flag-day' => '06-20',
            'substitutes-flag-day' => '= 06-20 if Tuesday then previous Monday and if Thursday then next Friday',
            'independence-day'  => '07-09',
            'anniversary-of-the-death-of-general-josyo-de-san-martyun'  => '= 08-17 if Tuesday then previous Monday and if Thursday then next Monday',
            'day-of-respect-for-cultural-diversity'   => '= 10-12 if Tuesday,Wednesday then previous Monday and if Thursday,Friday,Saturday,Sunday then next Monday',
            'substitutes-day-of-respect-for-cultural-diversity'=> '10-08',
            'day-of-national-sovereignty'  => '11-20',
            'substitutes-soberany-day'   => '= 11-20 if Tuesday,Wednesday then previous Monday and if Thursday,Friday,Saturday,Sunday then next Monday',
            'virgin-day' => '12-08',
            'substitutes-virgin-day'   => '= 12-08 if Tuesday then previous Monday and if Thursday then next Friday',
            'noche-buena'   => '12-24',
            'christmas'   => '12-25',
            'substitutes-christmas'   => '= 12-25 if Tuesday then previous Monday and if Thursday then next Friday',
            'noche-vieja'  => '12-31',
        ],
        // extra work days (even if in the weekend)
        'without' => [],
    ],
];

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

I tried your settings but couldn't reproduce the error using the live editor

Would you be able to give a minimum code chunk to reproduce on https://try-carbon.herokuapp.com/ please?

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

Could you also give me your PHP version running this (replacing now()->isHoliday() with echo PHP_VERSION; and running the code the same way you got the error).

from business-day.

mpoma avatar mpoma commented on June 29, 2024

I made some tests.
echo PHP_VERSION; 7.4.3 No errors

If I delete the config file and use enable with baselist = 'us-national', get the same warning;
Then I upload the project to a server and in artisan tinker get the same warning;
Because I get the library this weekend, I dont have especial code involve, just a simple check isHoliday(), is a big project with Laravel Nova.

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

Creating a Laravel project from scratch and running now()->isHoliday() causes no issues, so I can't figure out without a code chunk able to reproduce the bug. Please try to reduce it to the bare minimum to get the error occur, ideally outside Laravel.

from business-day.

mpoma avatar mpoma commented on June 29, 2024

OK, close the issue if you like. When I reproduce the bug, I'll contact you. Thanks for you attention (and your LIB)!!!

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

Actually errors at those lines are supposed to be muted (to fallback to static closure). So you should also check your error reporting setting. May you have something disabling @?

Also, can you check if this code reproduces your bug:

Carbon::macro('foo', static function () { return 'foo'; });
echo Carbon::foo();

If so, then your setup clearly has something incompatible with the whole macro system of Carbon.

Eventually, you may try to dump $macro at this point to see on which macro it fails.

from business-day.

mpoma avatar mpoma commented on June 29, 2024

this code
Carbon::macro('foo', static function () { return 'foo'; });
echo Carbon::foo();
work 'OK', without warning

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

What about the other question? Can you give the content of $macro on src/Carbon/Traits/Date.php on line 2413 when it fails?

I tried same with a fresh install of laravel 8.25.0. then requiring cmixin/business-day, copy-paste your config/carbon.php file then now()->isHoliday() worked just fine.

I can't help much more. I can just advise to try to start from a clean app an try to move pieces by chunk to see when it comes to throw the error so you might be able to produce a minimum code to reproduce, then I can add it to unit tests and fix it.

Thanks.

from business-day.

JWhiteSS avatar JWhiteSS commented on June 29, 2024

In my project, I have a shutdown function that will log an error if the return value of error_get_last() is an error. This warning was muted, however there is still an error. Is there a way to use this without generating errors (even if they're muted)?

from business-day.

kylekatarnls avatar kylekatarnls commented on June 29, 2024

Actually there is not much that can be done from business-day side.

This error is thrown and caught from Carbon side, and it's actually done this way because PHP provides no way to know if a given closure is static or not.

Only way would be a very verbose and heavy set_error_handler around each call that can throw a PHP error.

If you can use set_error_handler in your own application globally to throw ErrorException instead of native PHP error, you should no longer have this problem and possibly a better control over real PHP errors occurring.

from business-day.

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.