Skip to content

PHP 8.2.9: php artisan serve fails on parsing date #47930

@levu42

Description

@levu42

Laravel Version

10.17.0

PHP Version

8.2.9

Database Driver & Version

not relevant

Description

When using current Chrome or Fireox on Linux trying to access a Laravel installation served by php artisan serve on localhost:9000, during serving the first request, ServeCommand fails in getDateFromLine with a Carbon exception about an unexpected format.

The reason is that the date string seems to have two spaces between the month and day:


    protected function getDateFromLine($line)
    {
        $regex = env('PHP_CLI_SERVER_WORKERS', 1) > 1
            ? '/^\[\d+]\s\[([a-zA-Z0-9: ]+)\]/'
            : '/^\[([^\]]+)\]/';

        preg_match($regex, $line, $matches);
        dd($line, $matches);

        return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
    }


"[Wed Aug  2 11:30:23 2023] 127.0.0.1:46238 Accepted" // vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:309
array:2 [ // vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:309
  0 => "[Wed Aug  2 11:30:23 2023]"
  1 => "Wed Aug  2 11:30:23 2023"
]

When changing the createFromFormat argument to 'D M d H:i:s Y' (note the two spaces) it works perfectly fine.

I just upgraded PHP from 8.2.8 to 8.2.9, and it started after that, so that's potentially related.

Steps To Reproduce

  • Use Linux (not sure if that's a requirement, maybe it's also broken on other platforms?)
  • Install PHP 8.2.9
  • laravel new foo
  • cd foo
  • php artisan serve
  • Navigate to http://localhost:8000
  • Check command line output, notice an exception:
   Carbon\Exceptions\InvalidFormatException 

  Unexpected data found.

  at vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:687
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions