php的继承问题
我有两个类classmWorktime{staticprotected$table="worktime";//本类对应的表staticpublicfunctiondele...
我有两个类
class mWorktime
{
static protected $table = "worktime";//本类对应的表
static public function delete($id)
{
echo self::$table;
}
}
class mWorktime_tmp extends mWorktime
{
static protected $table = "worktime_tmp";//本类对应的表
}
mWorktime_tmp::delete(1);
输出的是父类的静态变量,怎么让他们输出各自的,又可以继承
这个是php5.2的结果 使用php 5.3 5.4会不会有变化? 展开
class mWorktime
{
static protected $table = "worktime";//本类对应的表
static public function delete($id)
{
echo self::$table;
}
}
class mWorktime_tmp extends mWorktime
{
static protected $table = "worktime_tmp";//本类对应的表
}
mWorktime_tmp::delete(1);
输出的是父类的静态变量,怎么让他们输出各自的,又可以继承
这个是php5.2的结果 使用php 5.3 5.4会不会有变化? 展开
2个回答
展开全部
class mWorktime {
static protected $table = "worktime"; //本类对应的表
}
class mWorktime_tmp extends mWorktime {
static protected $table = "worktime_tmp"; //本类对应的表
static public function delete($id) {
if ($id == 1) {
echo parent::$table;
} else {
echo self::$table;
}
}
}
mWorktime_tmp::delete(1);
mWorktime_tmp::delete(2);
//这样?
static protected $table = "worktime"; //本类对应的表
}
class mWorktime_tmp extends mWorktime {
static protected $table = "worktime_tmp"; //本类对应的表
static public function delete($id) {
if ($id == 1) {
echo parent::$table;
} else {
echo self::$table;
}
}
}
mWorktime_tmp::delete(1);
mWorktime_tmp::delete(2);
//这样?
更多追问追答
追问
哈哈 刚才百度那个对话框没操作好 这不是写上了嘛^_^
不行 父类也需要这个函数
追答
class mWorktime {
static protected $table = "worktime"; //本类对应的表
static public function delete() {
echo self::$table;
}
}
class mWorktime_tmp extends mWorktime {
static protected $table = "worktime_tmp"; //本类对应的表
static public function delete() {
parent::delete();
echo self::$table;
}
}
mWorktime_tmp::delete();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询