Php 分析错误:语法错误,意外[
我有一个简单的函数Php 分析错误:语法错误,意外[,php,hosting,Php,Hosting,我有一个简单的函数 function render($template, $values = []) { // if template exists, render it if (file_exists("../templates/$template")) { // extract variables into local scope extract($values); // render header
function render($template, $values = [])
{
// if template exists, render it
if (file_exists("../templates/$template"))
{
// extract variables into local scope
extract($values);
// render header
require("../templates/header.php");
// render template
require("../templates/$template");
// render footer
require("../templates/footer.php");
}
// else err
else
{
trigger_error("Invalid template: $template", E_USER_ERROR);
}
当我在本地主机上工作时,这很好,但是当我在我的Web主机上上传文件时,这个函数在php文件中使用,如下->
<?php
// configuration
require("../includes/config.php");
render("mainpage_template.php", ["title" => "Welcome "]);
?>
我将此解析错误写入标题中。为什么它仅在我的本地计算机上工作?您是否在本地计算机上使用php 5.4?渲染行正在使用初始化数组的新方法。请尝试将
[“title”=>“Welcome”]
替换为数组(“title”=>“Welcome”)
您在Web主机上运行的是什么版本的PHP?在5.4中添加了文字数组符号,因此[]
在5.3中不起作用。您在哪一行缺少[]?你能粘贴你收到的全部错误吗?顺便说一句,require
不是一个函数,你不必添加括号。@VladGincher:echo
,print
也不是函数,但你仍然可以添加括号。不要教别人错误的东西。@Glavić,我不是说他不能,我说他不必使用它们。M也许我说错了,我是指(
和)
。