首页 > 解决方案 > PHP:在 PHP/Laravel 中的“死”函数之后执行代码

问题描述

我是 PHP 新手,我想开始我从另一个来源复制的 laravel 项目。我收到 500 错误。如果我尝试调试公用文件夹中的 index.php,我会得到一个奇怪的行为,die如果代码中的内核行在那里,该函数不起作用。我不明白,我认为该die函数会停止执行。

<?php

die ('hi'); //this die

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
    require __DIR__.'/../storage/framework/maintenance.php';
}



require __DIR__.'/../vendor/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';

//If I comment out kernel line "die" on top doesn't return 'hi'. The response is 500 html code.
//$kernel = $app->make(Kernel::class);
/*
$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);
*/

编辑:来自服务器访问日志的获取日志是:

"GET /index2.php HTTP/2.0" 500 86 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"

我在错误日志中没有收到任何错误。所以我已经激活了 PHP 错误日志。我收到此错误消息:

[24-Sep-2020 11:00:39 Europe/Berlin] PHP Parse error:  syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /usr/.../inertia/public/index2.php on line 44

标签: laravelinstallationdie

解决方案


因此,在谷歌搜索 PHP 错误消息后,我发现我的 PHP 版本是 5.6 而不是 7.4,这是一个问题。谢谢大家的帮助!这对我帮助很大。公共文件夹中laravel有 .htaccess 文件。此文件已将 PHP 版本覆盖为默认 PHP 版本 5.6。


推荐阅读