php樣本的錯誤記錄

來源:互聯網
上載者:User

標籤:測試   size   strong   var   index.php   isp   http   this   www.   

最近幾天在測試php的mvc,從網上找到幾個樣本。

先學習這一篇,http://www.cnblogs.com/q1ng/p/4529496.html

標題是  PHP的MVC架構 深入解析,其實是最簡單的,感謝Q1NG的代碼。

有了第一篇的基礎,學習第二篇,http://www.cnblogs.com/foonsun/p/5788564.html

標題是 php簡單實現MVC,和第一篇差不多,內容更進一步了。卻叫簡單實現,這位仁兄挺謙虛。感謝喬曉峰的代碼。

第一篇沒錯,很順利,第二篇有錯誤。

 

第二篇,視圖View這一節課中,參數錯誤,無法開啟頁面

原始碼無法執行,會提示定義錯誤,Notice: Undefined variable:

 // controller/democontroller.php
 class DemoController
 {
     private $data = ‘Hello furzoom!‘;
     public function index()
     {
     //echo ‘hello world‘;
     require(‘view/index.php‘);
     $view = new Index();
     $view->display($data);
     }
 }// End of the class DemoController
 // End of file democontroller.php

改成

 // controller/democontroller.php
 class DemoController
 {
     private $data = ‘Hello furzoom!‘;
     public function index()
     {
     //echo ‘hello world‘;
     require(‘view/index.php‘);
     $view = new Index();
     $view->display($this->data);
     }
 }// End of the class DemoController
 // End of file democontroller.php

注意,$view->display($data);改成$view->display($this->data);

 

順手記一下,做類的建構函式時,使用舊式寫法比較安全些。

下面這個代碼是另一篇教程中的,無法執行,代碼錯誤,

地址 http://www.cnblogs.com/soundcode/p/6903826.html   感謝左正的代碼。

class test
{ var $b;
function test() { $this->b=5; }
function addab($c) { return $this->b+$c; }
}
$a = new test(); echo $a->addab(4); // 返回 9

改成下面這樣就可以了。

class test
{ var $b;
function __construct() { $this->b=5; }
function addab($c) { return $this->b+$c; }
}
$a = new test(); echo $a->addab(4); // 返回 9

 

php樣本的錯誤記錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.