不可以。您不能在類塊中放置自定義代碼(這裏是您的變量)。
如果您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