[英]Laravel Undefined array key 1 php artisan serve
Undefined array key 1
at D:\App-PHP\xampp_php_8\htdocs\test-project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:289
285▕ protected function getDateFromLine($line)
286▕ {
287▕ preg_match('/^\[([^\]]+)\]/', $line, $matches);
288▕
➜ 289▕ return Carbon::createFromFormat('D M d H:i:s Y', $matches[1]);
290▕ }
291▕
292▕ /**
293▕ * Get the request port from the given PHP server output.
1 D:\App-PHP\xampp_php_8\htdocs\test-project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:289
Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 1", "D:\App-PHP\xampp_php_8\htdocs\test-project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")
2 D:\App-PHP\xampp_php_8\htdocs\test-project\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:239
Illuminate\Foundation\Console\ServeCommand::getDateFromLine("27.0.0.1:65342 Accepted")
D:\App-PHP\xampp_php_8\htdocs\test-project>
我在本地運行 laravel 9 和 xampp-windows-x64-8.1.6-0-VS16-installer,使用 php artisan serve,然后它正常工作。 但是當我在 windows 服務器上與 xampp 一起運行時,就像我的本地服務器一樣,使用相同的 laravel 應用程序,第一次重新加載運行正常,但第二次重新加載它在 cmd 控制台上顯示錯誤 Undefined array key 1,並且應用程序停止工作。 我以前在 windows 服務器上運行的 laravel 應用程序從來沒有遇到過這種錯誤,順便說一句,我以前運行的應用程序是版本 8,這是我的第一個 laravel 9 應用程序,在 windows 服務器上。 謝謝之前
它基本上表明您的變量$matches
沒有索引[1]
。 您要么必須檢查條件是否已設置,要么如果它應該不是 null,您需要在它之前檢查一些代碼並驗證它為什么未定義。 現在,你可以這樣做:
return isset($matches[1]) ? Carbon::createFromFormat('D M d H:i:s Y', $matches[1]) : null;
試試這個對我有用的解決方案。
返回 isset($matches[1])? Carbon::createFromFormat('DM d H:i:s Y', $matches[1]): Carbon::now();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.