【发布时间】:2017-02-26 04:06:24
【问题描述】:
在下面的类中,实例化时,我收到以下错误:
'$this' (T_VARIABLE) 在第 12 行的代码中 'default_timestamp' => $this->_time,
我很困惑,因为当对象被实例化时,我假设 $_time 可以使用,但它似乎不是。我也试过'default_timestamp' => time(),但这也引发了错误。我是否误解了对象实例化?
class DateTimeHandler {
public $_date;
public $_time = 'xxx';
public $_datetime;
public $_timezone;
public $opts = array(
'default_timezone' => 'America/New_York',
'default_timestamp' => $this->_time,
'formats' => array(
'date' => 'Y-m-d',
'time' => 'g:ia',
'full' => 'Y-m-d H:i:s'
)
);
public function __construct() {
echo '<pre>', print_r( $this->opts, true );
}
}
$d = new DateTimeHandler();
【问题讨论】:
标签: php class object instantiation