2014-07-03 149 views
1

我剛剛開始學習面向對象的php,我遇到了我懷疑是一個非常微不足道的問題。我有兩個PHP文件,post.php中和testPost.php像這樣:面向對象的php

//post.php 
<?php 
    class fileWrite{ 
    public function postMessage($logId, $text, $username){ 
     //If the original login form was not used then this would not be set 
     date_default_timezone_set('Europe/London'); 

     $fp = fopen($logId, 'a'); 

     fwrite($fp, $text); 
     fclose($fp); 
    } 
} 
?> 

//testPost.php 
<?php 
    include 'post.php'; 
    $post = new fileWrite; 
    $post->postMessage("log.html", "test", "username"); 
?> 

當我運行testPost.php這是輸出:postMessage的( 「log.html」, 「測試」, 「用戶名」 ); ?>

任何幫助將不勝感激。

+2

查找文件中的拼寫錯誤,例如'$ post?> postMessage'而不是'$ post-> postMessage',這會結束'?>'處的代碼標記,並顯示其餘的代碼頁。 – Guffa

+0

您的「log.html」文件中可能只是簡單的,您可能需要檢查它。 – Mubo

+0

不知道爲什麼,但這段代碼在我的服務器上工作正常,但在我的電腦上完全沒有問題。 – whopit

回答

0

剛剛測試了您的代碼,它很好地工作,請檢查是否有錯字或您的腳本的擴展名爲.php。如果不是這樣會導致輸出字面上顯示您的代碼。