【问题标题】:class and include php类并包含 php
【发布时间】:2014-07-17 15:25:32
【问题描述】:

我正在从 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 结果后没有出现类破坏?? ?>

【问题讨论】:

  • "destruct" -- 你在那个脚本中做了什么吗?不。所以在脚本开始退出之前,您的对象不会被销毁。

标签: php class include


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-08-29
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2011-09-06
    • 2016-12-08
    • 1970-01-01
    相关资源
    最近更新 更多