【问题标题】:Symfony\Component\Debug\Exception\FatalThrowableError : syntax error, unexpected end of fileSymfony\Component\Debug\Exception\FatalThrowableError :语法错误,文件意外结束
【发布时间】:2022-01-21 04:35:30
【问题描述】:

当我运行这段代码时,我遇到了这个错误:Symfony\Component\Debug\Exception\FatalThrowableError : syntax error, unexpected end of file

point) 在 NGIX 中我没有任何问题,但现在我想在 laravelhomestead 中运行它,但它抛出了这个错误。

point2)这是路由器中的 content.php 文件

<?php

函数 extView($route) { $texts = [https://www.i-b.com/];

$mercati = ['banking-finance-fintech', 'insurance-insurtech', 'consumer-goods', 'industrial-goods', 'energy-utilities-infrastructure', 'luxury-fashion-design', 'sport-media-entertainment', 'pharma-medicine-healthcare', 'technology-telecom', 'public-sector', 'social-sector', 'private-equity'];

$servizi = ['strategy-governance', 'competitive-intelligence', 'innovation-management', 'ai-bigdata', 'marketing', 'sponsorship', 'sales', 'brand-communication', 'hr-organization', 'sustainability', 'ma'];

if (array_key_exists($route, $texts)) {
    return view('general-list', {$texts[$route]});
} else if (in_array($route, $mercati)) {
    return view('general-list', {$texts['banking-finance-fintech']});
} else if (in_array($route, $servizi)) {
    return view('general-list', {$texts['sponsorship']});
} else {
    abort(404);
}

}

enter image description here

【问题讨论】:

  • 你运行的代码是什么?
  • 我编辑并添加代码
  • 能否也添加完整的错误堆栈跟踪?
  • 另外,endif 在 PHP 中不是一个东西
  • 这就是重点。 PHP 认为他在对“endif”常量做他应该做的事情之前关闭了函数的括号

标签: php laravel homestead


【解决方案1】:

这是由于使用了 endif 关键字来标记 if 语句的结束,该语句以包含冒号的语法开始

if(...):
//..
elseif:
//..
else:
//.. 
endif;

但是,由于您使用的是花括号,因此在条件块末尾使用 endif 是不正确的语法,因此 syntax error

要修复此错误,只需从您的代码中删除 endif 关键字:

<?php


function extView($route)
{
    $texts = [];

$mercati = ['banking-finance-fintech', 'insurance-insurtech', 'consumer-goods', 'industrial-goods', 'energy-utilities-infrastructure', 'luxury-fashion-design', 'sport-media-entertainment', 'pharma-medicine-healthcare', 'technology-telecom', 'public-sector', 'social-sector', 'private-equity'];

    $servizi = ['strategy-governance', 'competitive-intelligence', 'innovation-management', 'ai-bigdata', 'marketing', 'sponsorship', 'sales', 'brand-communication', 'hr-organization', 'sustainability', 'ma'];

    if (array_key_exists($route, $texts)) {
        return view('general-list', {$texts[$route]});
    } else if (in_array($route, $mercati)) {
        return view('general-list', {$texts['banking-finance-fintech']});
    } else if (in_array($route, $servizi)) {
        return view('general-list', {$texts['sponsorship']});
    } else {
        abort(404);
    }
    // dont use endif here

} 
?>

【讨论】:

  • 不,没有用
猜你喜欢
  • 1970-01-01
  • 2017-12-06
  • 1970-01-01
  • 2020-03-22
  • 1970-01-01
  • 2017-03-08
  • 2019-08-02
  • 2020-05-15
  • 2018-08-18
相关资源
最近更新 更多