调用非对象的成员函数?新的PHP

时间:2012-11-09 14:42:52

标签: php

这将是一个愚蠢的错误。 我得到上面的错误。当用户点击链接时它基本打开一个视图页面,该页面调用需要$ category的类。

<?php
  // Initialise the template
   require_once "/var/www/template/template.php";
   $template = new CHTemplate();


     // And create a cid object
    require_once "/var/www/Component/DisplayWIPOnLocation.php";
    $WIPProgress= new CHWIPProgress();

    if(isset($_GET['category'])){

    $content .= " <h3> Details for Component : $reference </h3> ";
    $bundle = $WIPProgres->GetProducts($_GET['category']);   
    $reference = $_GET['category'];

    // Now show the details
    foreach($bundle as $x){
        $content .= "
                    <table>
                        <tr><th> ProductNumber</th><td>" . $x['ProductNumber'] . "</td>        
     </tr>
                        <tr><th> Description </th><td>" . $x['Description'] . "</td></tr>
                    </table>
                    <br>";
      }






           }

           $template->SetTag("content", $content);
            echo $template->Display();

           ?>

班级中的对象

 public function GetProducts($category) {
    $sql = "SELECT DISTINCT `Stock`.`ProductNumber`,`Stock`.`Description`
            FROM Stock , TBOM
            WHERE  `TBOM`.`Component` = '" . $category. "'
                    AND `Stock`.`ProductNumber` = `TBOM`.`Product`           
        ";
        mysql_select_db(DB_DATABASE_NAME, $this->conn);
        $result = mysql_query($sql, $this->conn);
                    $num_rows = mysql_num_rows($result);
                    //echo "Number of rows : $num_rows";

        while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $return[] = $row;
        }
        return $return;
            return $num_rows; 
    }

2 个答案:

答案 0 :(得分:1)

错字:

$WIPProgress= new CHWIPProgress();
          ^^--- two s's

$bundle = $WIPProgres->GetProducts($_GET['category']);   
                    ^--- one S

e.g。你正在调用一个不存在的对象。

答案 1 :(得分:0)

这只是意味着认为的某个对象是一个对象,不是

例如:

$bundle = $WIPProgres->GetProducts($_GET['category']); //<< you left off an `s`

这是一个很大的 PEBKAC 错误。