$t="刘";
$a=new A($t);
$test=$a->test();
echo ($test);
class   A{
  public $name;
  public function _construct($iname)
  {
      $this->name=$iname;
  
  }  public function test ()
  {
  
    echo $this—>name;
  
  }}
//如上代码,为什么不能达到显示的效果?   小弟不才。代码丑陋,多多指点

解决方案 »

  1.   

    $test=$a->test();
    echo ($test);     ==>      $a->test();
    或者  在类方法test()里面用return替换掉echo
      

  2.   

    标错了。。
    $test=$a->test();
    echo ($test);  
     
    这两句改为: $a->test();
      

  3.   


    $t="刘";
    $a=new A($t);
    $a->test();class   A{
      public $name;
      public function _construct($iname)
      {
          $this->name=$iname;
      
      }  public function test ()
      {
      
        echo $this—>name;
      
      }}
    //这样改后 依然不行, 没有报错,但是应该打印 “刘”的吧, 但是没有任何显示
      

  4.   

    public function __construct($iname)
    是两个下划线
      

  5.   

    $t="刘";
    $a=new A($t);
    $test=$a->test();
    //此处无需输出 echo ($test);
    class   A{
      public $name;
      public function __construct($iname)  //此处更正 "_construct" 错误写法
      {
          $this->name=$iname;
      
      }  public function test ()
      {
      
        echo $this->name;  //此处更正 "$this——>name" 错误写法
      
      }}
      

  6.   


    $t="刘";
    $a=new A($t);
    $a->test();class   A{
      public $name;
       public function __construct($iname)
      {
          $this->name=$iname;
      
      }  public function test ()
      {
      
        echo $this->name;
      
      }}
    //还是有错无语啦  真佩服我自己  ,test() 方法的  -> 也错了  悲剧啊 。