Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7 nightly: Declaration of Carbon\Carbon::createFromFormat() should be compatible with... #282

Closed
Macsch15 opened this issue Mar 2, 2015 · 19 comments

Comments

@Macsch15
Copy link

Macsch15 commented Mar 2, 2015

My build on travis has an error after added PHP 7 nightly to the test matrix:

Declaration of Carbon\Carbon::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, DateTimeZone $object = NULL) in /home/travis/build/Macsch15/Tricolore/lib/Carbon/Carbon.php on line 2213 (code 2048)

Can someone confirm this issue?

@briannesbitt
Copy link
Owner

Yes... as per:

php/php-src@8e19705#commitcomment-9969747

@Macsch15
Copy link
Author

Macsch15 commented Mar 3, 2015

I see 😕
Carbon will have some fix for this?

@briannesbitt
Copy link
Owner

Yes we will, first RC isn't due until June though but we'll get something in soon enough. Interesting though PHP 7 was just added to the test matrix and its passing... guess the referenced changed hasn't been merged yet for travis.
https://travis-ci.org/briannesbitt/Carbon/jobs/52878652

@Macsch15
Copy link
Author

My build is failing because I convert all PHP errors (even notices) into exceptions, you have in build only notice "PHP Strict Standards..." https://travis-ci.org/briannesbitt/Carbon/jobs/52878652

@kenmulford
Copy link

I don't have time to do a PR (or more honestly, learn about PRs because I've never done one), but I'm using Rasmus' php7dev vagrant box and ran across this error. I seed 30ish tables with Laravel's artisan db:seed command and they all require Carbon timestamps. I was able to get the seeding working correctly by changing the arguments for this method (line 379 or thereabouts) from

createFromFormat($format, $time, $tz = null)
to
createFromFormat($format, $time, DateTimeZone $tz = null)

The seeding was successful after this change.

Hope that's useful.

@Macsch15
Copy link
Author

@kenmulford this solution works fine on php 7 or later but on php 5 throws errors.

@kenmulford
Copy link

Correct, I should have clarified it's a b/c break. I was thinking it'd be useful in the context of the php7 test builds for anyone else trying to test apps.

@mririgoyen
Copy link

Now that 7.0.0alpha 1 is out, do we have a fix or workaround for this? A brand new Laravel 5.1 project fails with this exception.

@briannesbitt
Copy link
Owner

Still lots of conversation here: php/php-src@8e19705#commitcomment-11644892

@securit
Copy link

securit commented Jun 21, 2015

I got this to work across PHP versions by adding a simple php version check in Carbon.php from line 374

public static function createFromFormat($format, $time, $dtz = null)
{
    if ($dtz !== null) {
        if (phpversion() < 7) {
            $dt = $dtz;
        } else {
            $dt = new DateTimeZone;
            $dt = $dtz;
        }
        $dt = parent::createFromFormat($format, $time, static::safeCreateDateTimeZone($tz));
    } else {
        $dt = parent::createFromFormat($format, $time);
    }

@Denoder
Copy link

Denoder commented Jul 1, 2015

so uhh, when will this be fixed?

@GrahamCampbell
Copy link
Contributor

This is fixed.

@GrahamCampbell
Copy link
Contributor

alpha 2 fixed it

@Macsch15
Copy link
Author

Macsch15 commented Jul 3, 2015

Yes, looks like it has been fixed.

@GrahamCampbell
Copy link
Contributor

This issue can be closed now. :)

@Macsch15 Macsch15 closed this as completed Jul 3, 2015
@nWidart
Copy link

nWidart commented Jul 6, 2015

I still have this error on php7 & carbon.

@GrahamCampbell
Copy link
Contributor

It was fixed on alpha 2.

@GrahamCampbell
Copy link
Contributor

You must be using an older version of php7.

@nWidart
Copy link

nWidart commented Jul 6, 2015

Indeed, had to re-compile php7. Thanks for the heads up & sorry for the trouble. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants