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

Unexpected data found PHP 8.2.9 (remirepo) Fedora 38 #47922

Closed
Stenfrank opened this issue Aug 2, 2023 · 5 comments
Closed

Unexpected data found PHP 8.2.9 (remirepo) Fedora 38 #47922

Stenfrank opened this issue Aug 2, 2023 · 5 comments

Comments

@Stenfrank
Copy link

Laravel Version

10.17.0

PHP Version

8.2.9

Database Driver & Version

No response

Description

Starting the development server and accessing the url "http://127.0.0.1:8000" generates the following error:

INFO  Server running on [http://127.0.0.1:8000].  

 Press Ctrl+C to stop the server


  Carbon\Exceptions\InvalidFormatException 

 Unexpected data found.

 at vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:687
   683▕             return $instance;
   684▕         }
   685▕ 
   686▕         if (static::isStrictModeEnabled()) {
 ➜ 687▕             throw new InvalidFormatException(implode(PHP_EOL, $lastErrors['errors']));
   688▕         }
   689▕ 
   690▕         return false;
   691▕     }

     +22 vendor frames 

 23  artisan:35
     Illuminate\Foundation\Console\Kernel::handle()

Log:

[2023-08-02 02:17:01] local.ERROR: Unexpected data found. {"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): Unexpected data found. at /test/laravel_10/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:687)
[stacktrace]
#0 /test/laravel_10/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(710): Carbon\\Carbon::rawCreateFromFormat()
#1 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php(310): Carbon\\Carbon::createFromFormat()
#2 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php(253): Illuminate\\Foundation\\Console\\ServeCommand->getDateFromLine()
#3 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(236): Illuminate\\Foundation\\Console\\ServeCommand->Illuminate\\Foundation\\Console\\{closure}()
#4 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php(237): Illuminate\\Support\\Collection->each()
#5 /test/laravel_10/vendor/symfony/process/Process.php(1276): Illuminate\\Foundation\\Console\\ServeCommand->Illuminate\\Foundation\\Console\\{closure}()
#6 /test/laravel_10/vendor/symfony/process/Process.php(1376): Symfony\\Component\\Process\\Process->Symfony\\Component\\Process\\{closure}()
#7 /test/laravel_10/vendor/symfony/process/Process.php(1296): Symfony\\Component\\Process\\Process->readPipes()
#8 /test/laravel_10/vendor/symfony/process/Process.php(840): Symfony\\Component\\Process\\Process->updateStatus()
#9 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php(92): Symfony\\Component\\Process\\Process->isRunning()
#10 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Foundation\\Console\\ServeCommand->handle()
#11 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#13 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#14 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call()
#15 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\\Container\\Container->call()
#16 /test/laravel_10/vendor/symfony/console/Command/Command.php(326): Illuminate\\Console\\Command->execute()
#17 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\\Component\\Console\\Command\\Command->run()
#18 /test/laravel_10/vendor/symfony/console/Application.php(1081): Illuminate\\Console\\Command->run()
#19 /test/laravel_10/vendor/symfony/console/Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand()
#20 /test/laravel_10/vendor/symfony/console/Application.php(174): Symfony\\Component\\Console\\Application->doRun()
#21 /test/laravel_10/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\\Component\\Console\\Application->run()
#22 /test/laravel_10/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle()
#23 {main}
"} 

Creator.php function rawCreateFromFormat:

/**
     * Create a Carbon instance from a specific format.
     *
     * @param string                         $format Datetime format
     * @param string                         $time
     * @param DateTimeZone|string|false|null $tz
     *
     * @throws InvalidFormatException
     *
     * @return static|false
     */
    public static function rawCreateFromFormat($format, $time, $tz = null)
    {
        // Work-around for https://bugs.php.net/bug.php?id=80141
        $format = preg_replace('/(?<!\\\\)((?:\\\\{2})*)c/', '$1Y-m-d\TH:i:sP', $format);

        if (preg_match('/(?<!\\\\)(?:\\\\{2})*(a|A)/', $format, $aMatches, PREG_OFFSET_CAPTURE) &&
            preg_match('/(?<!\\\\)(?:\\\\{2})*(h|g|H|G)/', $format, $hMatches, PREG_OFFSET_CAPTURE) &&
            $aMatches[1][1] < $hMatches[1][1] &&
            preg_match('/(am|pm|AM|PM)/', $time)
        ) {
            $format = preg_replace('/^(.*)(?<!\\\\)((?:\\\\{2})*)(a|A)(.*)$/U', '$1$2$4 $3', $format);
            $time = preg_replace('/^(.*)(am|pm|AM|PM)(.*)$/U', '$1$3 $2', $time);
        }

        if ($tz === false) {
            $tz = null;
        }

        // First attempt to create an instance, so that error messages are based on the unmodified format.
        $date = self::createFromFormatAndTimezone($format, $time, $tz);
        $lastErrors = parent::getLastErrors();
        /** @var \Carbon\CarbonImmutable|\Carbon\Carbon|null $mock */
        $mock = static::getMockedTestNow($tz);

        if ($mock && $date instanceof DateTimeInterface) {
            // Set timezone from mock if custom timezone was neither given directly nor as a part of format.
            // First let's skip the part that will be ignored by the parser.
            $nonEscaped = '(?<!\\\\)(\\\\{2})*';

            $nonIgnored = preg_replace("/^.*{$nonEscaped}!/s", '', $format);

            if ($tz === null && !preg_match("/{$nonEscaped}[eOPT]/", $nonIgnored)) {
                $tz = clone $mock->getTimezone();
            }

            // Set microseconds to zero to match behavior of DateTime::createFromFormat()
            // See https://bugs.php.net/bug.php?id=74332
            $mock = $mock->copy()->microsecond(0);

            // Prepend mock datetime only if the format does not contain non escaped unix epoch reset flag.
            if (!preg_match("/{$nonEscaped}[!|]/", $format)) {
                $format = static::MOCK_DATETIME_FORMAT.' '.$format;
                $time = ($mock instanceof self ? $mock->rawFormat(static::MOCK_DATETIME_FORMAT) : $mock->format(static::MOCK_DATETIME_FORMAT)).' '.$time;
            }

            // Regenerate date from the modified format to base result on the mocked instance instead of now.
            $date = self::createFromFormatAndTimezone($format, $time, $tz);
        }

        if ($date instanceof DateTimeInterface) {
            $instance = static::instance($date);
            $instance::setLastErrors($lastErrors);

            return $instance;
        }

        if (static::isStrictModeEnabled()) {
            throw new InvalidFormatException(implode(PHP_EOL, $lastErrors['errors']));
        }

        return false;
    }

Dump($format, $time, $tz = null) InvalidFormatException:

GET http://localhost/
---------------------

 ------------ ---------------------------------------------------- 
  date         Wed, 02 Aug 2023 02:19:40 +0000                     
  controller   null                                                
  source       Creator.php on line 687                             
  file         vendor/nesbot/carbon/src/Carbon/Traits/Creator.php  
 ------------ ---------------------------------------------------- 

"D M d H:i:s Y"

 ------------ ---------------------------------------------------- 
  date         Wed, 02 Aug 2023 02:19:40 +0000                     
  controller   null                                                
  source       Creator.php on line 687                             
  file         vendor/nesbot/carbon/src/Carbon/Traits/Creator.php  
 ------------ ---------------------------------------------------- 

"Tue Aug  1 21:19:39 2023"

 ------------ ---------------------------------------------------- 
  date         Wed, 02 Aug 2023 02:19:40 +0000                     
  controller   null                                                
  source       Creator.php on line 687                             
  file         vendor/nesbot/carbon/src/Carbon/Traits/Creator.php  
 ------------ ---------------------------------------------------- 

null

Steps To Reproduce

  1. php artisan serve
  2. To access http://127.0.0.1:8000
@Stenfrank Stenfrank changed the title Unexpected data found PHP 8.2.9 Fedora 38 Unexpected data found PHP 8.2.9 (remirepo) Fedora 38 Aug 2, 2023
@crynobone

This comment was marked as off-topic.

@crynobone
Copy link
Member

Hey there,

It seems that for some reason Fedora is outputting D M d H:i:s Y instead of D M d H:i:s Y (two space between M and d which cause the issue. This could be an issue of incorrect DateTme format from Fedora and maybe an OS configuration.

While this may be a legitimate issue, can you first try posting your problem or question on one of the support channels below? If this issue can be definitively identified as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

@esistgut
Copy link

esistgut commented Aug 2, 2023

This is happening on Arch too after upgrading PHP to 8.2.9.
Related: php/php-src#11854

@josmarh
Copy link

josmarh commented Sep 2, 2023

This happened while still on my dev environment on my windows PC. i just upgraded to PHP 8.2

Carbon\Exceptions\InvalidFormatException 
Unexpected data found.

at vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:687
    683▕             return $instance;
    684▕         }
    685▕
    686▕         if (static::isStrictModeEnabled()) {
  ➜ 687▕             throw new InvalidFormatException(implode(PHP_EOL, $lastErrors['errors']));
    688▕         }
    689▕
    690▕         return false;
    691▕     }

  1   vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:710
      Carbon\Carbon::rawCreateFromFormat("D M d H:i:s Y", "Sat Sep  2 18:11:49 2023")

  2   vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:310
      Carbon\Carbon::createFromFormat("D M d H:i:s Y", "Sat Sep  2 18:11:49 2023")

@josuejunior2
Copy link

josuejunior2 commented Sep 2, 2023

This also happened to me on my windows pc. php version: 8.2.9
`Carbon\Exceptions\InvalidFormatException

Unexpected data found.

at vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:687
683▕ return $instance;
684▕ }
685▕
686▕ if (static::isStrictModeEnabled()) {
➜ 687▕ throw new InvalidFormatException(implode(PHP_EOL, $lastErrors['errors']));
688▕ }
689▕
690▕ return false;
691▕ }

1 vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:710
Carbon\Carbon::rawCreateFromFormat()

2 vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:303
Carbon\Carbon::createFromFormat()`

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

5 participants