我收到此错误解析错误:语法错误,意外'['

时间:2013-09-27 16:41:50

标签: php

<?php

    // configuration
    require("../includes/config.php"); 

     render("home_form.php", ["title" => "Log In"]);
?>


  /**
     * Renders template, passing in values.
     */
    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);
        }
    }

2 个答案:

答案 0 :(得分:3)

替换render("home_form.php", ["title" => "Log In"]);render("home_form.php", array("title" => "Log In"));

$values = []

$values = array()

答案 1 :(得分:0)

您使用哪个PHP版本?

自PHP 5.4.0以来,可以使用短数组语法:http://php.net/manual/en/migration54.new-features.php