我有一堂课。基本上构造和setter函数是相同的。一切都以这种方式工作得很好。但是当我尝试从构造函数中删除相同的代码,而只是调用 setter 函数时,我收到了一个致命错误:“致命错误:当不在对象上下文中时使用 $this...”这是之前的代码更改(这工作正常,没有错误)
Class Zmanim extends ZmanimCalculation {
//this class contains all the stuff needed in order to make the zmanim page work
private $day_const,$month_const,$year_const,$latitude_const,$longitude_const,$tz_const,$date_convertor_const,$zmanim_array_const;
function __construct($set_day,$set_month,$set_year,$set_latitude,$set_longitude,$set_tz,$set_date_convertor=true) {
$this->day_const=$set_day;
$this->month_const=$set_month;
$this->year_const=$set_year;
$this->latitude_const=$set_latitude;
$this->longitude_const=$set_longitude;
$this->tz_const=$set_tz;
$this->date_convertor_const=$set_date_convertor;
$this->zmanim_array_const=ZmanimCalculation::Full_Zmanim_calculation ($this->day_const,$this->month_const,$this->year_const,$this->latitude_const,$this->longitude_const,$this->tz_const,$this->date_convertor_const);
}
static function setZmanim ($set_day,$set_month,$set_year,$set_latitude,$set_longitude,$set_tz,$set_date_convertor=true) {
$this->day_const=$set_day;
$this->month_const=$set_month;
$this->year_const=$set_year;
$this->latitude_const=$set_latitude;
$this->longitude_const=$set_longitude;
$this->tz_const=$set_tz;
$this->date_convertor_const=$set_date_convertor;
$this->zmanim_array_const=ZmanimCalculation::Full_Zmanim_calculation ($this->day_const,$this->month_const,$this->year_const,$this->latitude_const,$this->longitude_const,$this->tz_const,$this->date_convertor_const);
}
这就是我调用构造的方式(仍然可以正常工作而没有错误:
$fullzmanim=new Zmanim ($_POST['zmanim_gregorian_day'],
$_POST['zmanim_gregorian_month'],
$_POST['zmanim_gregorian_year'],
$latitude,
$longitude,
$tz);
但是当我只是在构造函数中调用 setter 静态函数时,我得到了一个错误。这是错误的代码:
Class Zmanim extends ZmanimCalculation {
//this class contains all the stuff needed in order to make the zmanim page work
private $day_const,$month_const,$year_const,$latitude_const,$longitude_const,$tz_const,$date_convertor_const,$zmanim_array_const;
function __construct($set_day,$set_month,$set_year,$set_latitude,$set_longitude,$set_tz,$set_date_convertor=true) {
self::setZmanim($set_day,$set_month,$set_year,$set_latitude,$set_longitude,$set_tz,$set_date_convertor);
}
static function setZmanim ($set_day,$set_month,$set_year,$set_latitude,$set_longitude,$set_tz,$set_date_convertor=true) {
$this->day_const=$set_day;
$this->month_const=$set_month;
$this->year_const=$set_year;
$this->latitude_const=$set_latitude;
$this->longitude_const=$set_longitude;
$this->tz_const=$set_tz;
$this->date_convertor_const=$set_date_convertor;
$this->zmanim_array_const=ZmanimCalculation::Full_Zmanim_calculation ($this->day_const,$this->month_const,$this->year_const,$this->latitude_const,$this->longitude_const,$this->tz_const,$this->date_convertor_const);
}
有人知道出了什么问题吗?谢谢!