2014-07-17 79 views
0

我正在從新的論壇的新項目從0,我想添加一個很好的方法和...等 1.第一: 我想調用一個文件的類在一個類中,我的意思是: 我有一個文件class.php例如,autoe main.php和index.php 在class.php我讓我的類,並在main.php我創建auther類主,我包括裏面class.php,之後我使用的功能就像一個類...類和包括php

class.php:

<?PHP 
      class test{ 
        function hello(){ echo "Hello World !"; } 
      } 
    ?> 

main.php

<?PHP 
     class main{ 
     function _test_(){ 
     require_once("class.php"); 
     return new test(); 
      } 
     function __destruct(){ 
      echo "good bye"; 
      } 
     } 

的index.php:

<?PHP 
    include_once("main.php"); 
    $main = new main(); 
    $main->_test_()->hello(); 
    echo "<br> what !!!!???? <br>"; 
?> 

現在的結果是:

Hello World ! 
what !!!!???? 
good bye 

我想知道爲什麼類破壞後的Hello World結果沒有apear? >

+0

「destruct」 - 你在做那個劇本嗎?不可以。因此,在腳本開始退出之前,您的對象不會被銷燬。 –

+0

**謝謝:) ** – user136389

回答

4

因爲that's how it's designed是:

析構函數方法進行,只要存在要以任何順序的特定對象,或關機 序列期間沒有其他 引用調用。