类和包括PHP

时间:2014-07-17 15:25:32

标签: php class include

我从0开始在新论坛的新项目中工作,我想添加一个不错的方法和...等 1.第一: 我试图在类中调用文件的类,我的意思是: 我有一个文件class.php,例如auther main.php和index.php 在class.php中,我创建了我的类,并且在main.php中我创建了auther类main,我在class.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结果之后,类破坏没有出现? ?&GT;

1 个答案:

答案 0 :(得分:4)

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

  

只要没有其他方法,就会调用析构函数方法   对特定对象的引用,或者在关闭期间以任何顺序   序列