很简单的几行代码,麻烦请高手替我讲解一下调用的思路。①new_1.php
<?php
function the1test(){
echo "the1test!";
the2test();
}
?>②new_2.php
<?php 
function the2test(){
echo "the2test!";
}
?>③total.php
<?php
require_once("new_1.php");
require_once("new_2.php");
?>④testpage.php
<?php
require_once("total.php");
the1test();
?>接下来是我自己测试的结果。发现输出的结果是:the1test!the2test!我有一点疑问,为什么在new_1.php中能够直接调用new_2.php中的the2test()函数。难道是因为total.php的原因吗?这一点我始终没能理解到,谢谢!

解决方案 »

  1.   

    你不是已经 require_once("new_2.php"); 了吗?
      

  2.   

    total.php 中不是有require_once("new_2.php");吗?当然就可以调用了。
      

  3.   

    total.php 中已经require_once("new_1.php");require_once("new_2.php");
    等于都是在total.php中执行的,和new_1.php没有直接关系了,并不是在new_1.php中执行
      

  4.   

    代码没有问题
    testpage.php
    等于<?php
    // require_once('total.php');
    function the1test(){
    echo "the1test!";
    the2test();
    }function the2test(){
    echo "the2test!";
    }the1test();
    ?>
      

  5.   

    new1和new2只是函数定义实际函数调用是在testpage.php