<?php
class abhi
{
var $contents="default_abhi";
function abhi($contents)
{
$this->$contents = $contents;
}
function get_whats_there()
{
return $this->$contents;
}
}
$abhilash = new abhi("abhibutu");
echo $abhilash->get_whats_there();
?>
我已经初始化变量内容的默认和构造函数,为什么值不打印,我应该在这里纠正什么?php代码没有执行?
看到错误,
[email protected]:~$ php5 pgm2.php
Fatal error: Cannot access empty property in /home/abhilash/pgm2.php on line 13
[email protected]:~$
什么Extrakun意味着设置或获取对象的变量时,你不包括$。 – 2010-01-15 14:19:23
作业也是如此。 – falstro 2010-01-15 14:19:46
实际上还存在另一个问题...... echo语句在abhilash变量名称前需要一个美元符号。 – Narcissus 2010-01-15 14:26:50