關於PHP的解構函式問題

來源:互聯網
上載者:User
直接上代碼

class FileTest extends SplFileInfo{    public function __destruct(){        var_dump($this->getRealPath());    }}$file = new FileTest('index.php');  //boolean falsenew FileTest('index.php');  //'E:\Apache24\htdocs\index.php'

如以上代碼所示,同樣new一個對象,賦值給變數和沒賦值給變數結果卻不一樣,有人知道原因嗎?

回複內容:

直接上代碼

class FileTest extends SplFileInfo{    public function __destruct(){        var_dump($this->getRealPath());    }}$file = new FileTest('index.php');  //boolean falsenew FileTest('index.php');  //'E:\Apache24\htdocs\index.php'

如以上代碼所示,同樣new一個對象,賦值給變數和沒賦值給變數結果卻不一樣,有人知道原因嗎?

我在PHP5.6下跑出的結果:

D:\PHP5.6\php.exe E:\M5\carvincai\test\file.phpbool(false)bool(false)

能不能再提供一些更詳細的資訊?

更新:

我修改了一下代碼:

getRealPath());    }}$file = new FileTest(__FILE__);  //boolean falsenew FileTest(__FILE__);  //'E:\Apache24\htdocs\index.php'

結果:

D:\PHP5.6\php.exe E:\M5\carvincai\test\file.phpstring(29) "E:\M5\carvincai\test\file.php"string(29) "E:\M5\carvincai\test\file.php"

題主你是不是可以再檢查一下建構函式裡傳入的檔案名稱?

php 5.6 環境沒問題,結果一致
首先要確保 'index.php' 檔案是存在的
你肯定是在同一個環境下面執行了,使用了 'index.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.