请看以下代码,请大侠们帮忙,程序运行结果为什么只有“没有显示上一行的内容”
<?$b = new book("上帝原谅我");
$b->showTitle();
class book
{
var $title;

function book($t)
{
$title = $t;
}

function showTitle()
{
echo "$title";
echo "没有显示上一行的内容";
}


}
?>

解决方案 »

  1.   


    <? $b = new book("上帝原谅我"); 
    $b->showTitle(); 
    class book 

    var $title; function book($t) 

    $this->title = $t; 
    } function showTitle() 

    echo $this->title; 
    echo "没有显示上一行的内容"; 


    ?>
      

  2.   

    function book($t) 

    $this->title = $t; 

      

  3.   

    还真没看手册么?
    PHP对象构造函数是 function __construct()
      

  4.   

    function book($t)
    {
    $this->title = $t;
      

  5.   

    PHP4使用同名函数作为类的构造函数。
      

  6.   


    php5的构造函数是__construct().php4的不是.在类内部引用类属性或方法要用$this.