不可以。您不能在类块中放置自定义代码(这里是您的变量)。
如果您wan't到初始化类的字段,你可以使用类的构造函数
<?php
class booking_diary {
public $booking_start_time;
public $booking_end_time;
public $booking_frequency;
public function __construct() {
$start_timeS="09:30";
$bookingS_start_time= "19:00";
$bookingS_frequency=30;
//`enter code here`
$this->booking_start_time = $start_timeS;
$this->booking_end_time = $bookingS_start_time;
$this->booking_frequency = $bookingS_frequency;
}
}
如果你想养活从外部瓦尔类,也许这样的事情会适合您的需要:
<?php
class booking_diary {
public $booking_start_time;
public $booking_end_time;
public $booking_frequency;
public function __construct($booking_start_time, $booking_end_time, $booking_frequency) {
$this->booking_start_time = $booking_start_time;
$this->booking_end_time = $booking_end_time;
$this->booking_frequency = $booking_frequency;
}
}
// Somewhere in your code:
$start_timeS="09:30";
$bookingS_start_time= "19:00";
$bookingS_frequency=30;
//`enter code here`
$instance = new booking_diary($start_timeS, $bookingS_start_time, $bookingS_frequency);
来源
2015-02-23 12:08:37
Nat
试试吧?你的问题是什么?¨ – Rizier123 2015-02-23 11:59:41
为什么不自己尝试一下? – 2015-02-23 12:00:25