0

我有一个像这样的简单 php 页面:

<?php
include 'config.php';
include 'lib.php';
header("Content-type: text/html; charset=UTF-8");

?>

<html>
    <head>
        <title>view states</title>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
    </head>

    <body>

    <div id="container">
        WTF?
    </div>

    </body>

</html>

当我的 lib.php 中有下面的代码时,我的 dom 只包含一个头部和身体。标题不见了,div 容器不见了,文本 'wtf?' 还。

怎么了?

class State {
  $id;
  $ip;
  $state;
  $date;
  $played;

  function __construct($id, $ip, $state, $date, $played) {
     $this->$id = $id;
     $this->$ip = $ip;
     $this->$state = $$state;
     $this->$date = $date;
     $this->$played = $played;
  }


}
4

1 回答 1

0

打开错误报告,问题变得非常明显。您未能正确声明您的类变量

<?php
class State {
  protected $id;
  protected $ip;
  protected $state;
  protected $date;
  protected $played;

  function __construct($id, $ip, $state, $date, $played) {
     $this->id = $id;
     $this->ip = $ip;
     $this->state = $state;
     $this->date = $date;
     $this->played = $played;
  }


}
于 2012-10-04T16:43:25.393 回答