<?php
class testClass{
    private $a,$b;
    public function _construct($c,$d){
        $this->a=$c+99;
        $this->b=$d*99;
    }
    public function output(){
        echo 'the value of $a is '.$this->a.'<br/>';
        echo 'the value of $b is '.$this->b.'<br/>';
    }
}
$t=new testClass(88,44);
$t->output();
?>原本想输出的a和b的值分别是初始化过的,结果输出是空

解决方案 »

  1.   

    public function _construct($c,$d){ 的_construct少了_应该有两个
      

  2.   


    class testClass{
        private $a,$b;
        public function __construct($c,$d){
            $this->a=$c+99;
            $this->b=$d*99;
        }
        public function output(){
            echo 'the value of $a is '.$this->a.' <br/>';
            echo 'the value of $b is '.$this->b.' <br/>';
        }
    }
    $t=new testClass(88,44);
    $t->output(); 
    这样就对了
      

  3.   

    dzxccsu已经回答 向dzxccsu学习!