我正在寫一個簡單的課。下面是代碼:PHP中的字符串連接和類函數?
class Book{
var $title;
var $publishedDate;
function Book($title, $publishedDate){
$this->title = $title;
$this->publishedDate = $publishedDate;
}
function displayBook(){
echo "Title: " . $this->title . " published on " . $this->publishedDate . "";
}
function setAndDisplay($newTitle, $newDate){
$this->title = $newTitle;
$this->publishedDate = $newDate;
echo "The new information is of the book <b>" . $this->displayBook() . "</b><br />";
}
}
我初始化類和調用的函數:
$test = new Book("Harry Potter", "2010-1-10");
$test->setAndDisplay("PHP For Beginners", "2010-2-10");
,其結果是:
"Title: PHP For Beginners published on 2010-2-10The new information is of the book"
它不應該是:
"The new information is of the book **Title: PHP For Beginners published on 2010-2-10**
任何人都可以解釋一下嗎?
嗯......我明白了。所以我必須先儲存一個變量,然後再進行連接? – progamer 2010-11-10 03:07:27
@ wordpress_newbie - 對不起,我今天是打字員。看到我的編輯 – Phil 2010-11-10 03:11:55
嘿謝謝。現在我明白了:D – progamer 2010-11-10 03:12:58