【问题标题】:Fatal Error: Function name must be a string PHP Function [closed]致命错误:函数名称必须是字符串 PHP 函数 [关闭]
【发布时间】:2013-12-04 17:45:27
【问题描述】:

有人可以帮忙吗?我收到以下错误:Fatal Error: Function name must be a string in .... on line 120

这是代码 - 我看起来不错,但也许还有第二双眼睛?我将突出显示第 120 行。

function display($name, $display_name, $id, $package_results, $payment_type, $before_percent_box, $before_price_box, $after_percent_box, $after_price_box, $min_price_box)
{
    LINE 120 -> $records = $mysql_num_rows($package_results);   

    if ($records > 0)   //If there are records
    {
        while($package_row = mysql_fetch_assoc($results))
        {

        }
    }
    else    //If there were no records found
    {
        if ($payment_type == 1)     //If it is a PAYG
        {
            createPricePackageTable($name, $display_name, $id, "", $before_percent_box, $before_price_box, $after_percent_box, $after_price_box, $min_price_box, $records, 1);  //Create one blank table, 1 month
        }
        else    //If it is any other payment type other than PAYG
        {
            createPricePackageTable($name, $display_name, $id, "", $before_percent_box, $before_price_box, $after_percent_box, $after_price_box, $min_price_box, $records, 2);  //Create two blank tables, 6 and 12 months 
        }
    }
}

我还包含了导致调用上述函数的代码:

function build($name, $id, $memberid, $results) 
{
    echo "<div class='popup-column' style='width: 100%;'>";
        echo "<h3>Payment Option " . $memberid . "</h3>";

        echo "<p>Which payment options do you offer?</p>";

        echo "<div class='payment-options'>";
            $payment_type = 0;

            $display_name = $name;      //Get the name of the Payment Type
            $name = str_replace(" ", "", $name);

            $disable  = 'readonly="readonly" class="readonly"';
            $before_percent_box = '';   //Setup variables to hold whether a input box is disabled or not
            $before_price_box = '';
            $after_percent_box  = '';
            $after_price_box  = '';
            $min_price_box    = '';

            switch($name)   //Disable some input box fields
            {
                case "Split1" :
                    $payment_type = 5;

                    break;

                case "Split2" :
                    $payment_type = 6;

                    break;

                case "Fixed1" :
                    $payment_type = 3;

                    $before_percent_box = $disable;
                    $after_percent_box  = $disable;
                    $after_price_box  = $disable;
                    $min_price_box    = $disable;

                    break;

                case "Fixed2" :
                    $payment_type = 4;

                    $before_percent_box = $disable;
                    $after_percent_box  = $disable;
                    $after_price_box  = $disable;
                    $min_price_box    = $disable;

                    break;

                case "PAYG" :
                    $payment_type = 1;

                    $before_percent_box = $disable;
                    $after_percent_box  = $disable;
                    $after_price_box  = $disable;
                    $min_price_box    = $disable;

                    break;

                case "Commission" :
                    $payment_type = 2;

                    $before_percent_box = $disable;
                    $before_price_box = $disable;

                    break;
            }

            displayPackagePricesTable($name, $display_name, $id, $results, $payment_type, $before_percent_box, $before_price_box, $after_percent_box, $after_price_box, $min_price_box);    //Display the table with the prices

...

【问题讨论】:

  • $mysql_num_rowsnull
  • 这个问题似乎是题外话,因为它是关于一个错字。
  • 你真的需要学习如何阅读错误信息...
  • 另外,在相关说明中:mysql_* 函数不再维护,不应在任何新代码库中使用。它正在逐步淘汰,以支持更新的 API。相反,您应该将prepared statementsPDOMySQLi 一起使用。

标签: php mysql fatal-error


【解决方案1】:

由于可以调用variable function,PHP 尝试调用名为$mysql_num_rows 的函数。该变量未在您的代码中的任何地方定义,而是NULL。因此,您实际上会尝试调用名称为 not 字符串的函数,并导致 PHP 触发该致命错误。

将该行更改为:

$records = mysql_num_rows($package_results);   
          ^-- remove the $

【讨论】:

  • 啊,谢谢谢谢!
【解决方案2】:

您有一个以 $ 符号开头的函数名称。删除它:

$records = mysql_num_rows($package_results);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多