$t="刘"; $a=new A($t); $a->test();class A{ public $name; public function _construct($iname) { $this->name=$iname;
} public function test () {
echo $this—>name;
}} //这样改后 依然不行, 没有报错,但是应该打印 “刘”的吧, 但是没有任何显示
public function __construct($iname) 是两个下划线
$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" 错误写法
}}
$t="刘"; $a=new A($t); $a->test();class A{ public $name; public function __construct($iname) { $this->name=$iname;
echo ($test); ==> $a->test();
或者 在类方法test()里面用return替换掉echo
$test=$a->test();
echo ($test);
这两句改为: $a->test();
$t="刘";
$a=new A($t);
$a->test();class A{
public $name;
public function _construct($iname)
{
$this->name=$iname;
} public function test ()
{
echo $this—>name;
}}
//这样改后 依然不行, 没有报错,但是应该打印 “刘”的吧, 但是没有任何显示
是两个下划线
$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" 错误写法
}}
$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() 方法的 -> 也错了 悲剧啊 。