刚没说清楚,我要访问DD()class A
{
function DD()
{

} function AA()
{
function BB()
{
  //请问在这里如何访问DD()
}
}
}

解决方案 »

  1.   

    没有在class里面试过,
    不过
    function DD()
    {

    } function AA()
    {
    function BB()
    {
      DD();
    }
    }
    单纯的函数是可以这样使用的.
      

  2.   

    function DD()
    {

    } function AA()
    {
    function BB()
    {
      $this->DD();
    }
    }
      

  3.   

    $this->DD();
    不行,会出错的。
      

  4.   

    function f1(){

    function f2(){
    return 12;
    }
    return f2()+1;
    }echo f1();
      

  5.   

    因该说函数内的函数只能由包含他的函数访问
    类的方法可以用$this是因为隐式传递了一个引用
      

  6.   

    <?php
    class C{
    function D()
    {
    echo "C::D";
    }
    function A()
    {
    function B(&$class)
    {
    $class->D();
    }
    B(&$this);
    }
    }$c = new C;
    $c->A();
    ?>
      

  7.   

    php不能限制访问,那函数里套函数有什么意义呢?
      

  8.   

    不要钻牛角尖!花费了许多脑细胞,到php5下一切都完蛋了
    php5.0.2测试结果
    <?php
    class C{
    function D()
    {
    echo "C::D";
    }
    function A()
    {
    function B(&$class)
    {
    $class->D();
    }
    B(&$this);
    }
    }$c = new C;
    $c->A();
    ?>
    Fatal error: Non-static method C::B() cannot be called statically in ...\ide\tmp_ide.php on line 13
      

  9.   

    应该是用$this的吧...
    class Class
    {
    public function A()
    {
    //...
    return 0;
    } public function B()
    {
    $this->A();
    }
    }
    手册中的例子是这样:<?php
    class A
    {
        function example()
        {
            echo "I am the original function A::example().<br>\n";
        }
    }class B extends A
    {
        function example()
        {
            echo "I am the redefined function B::example().<br>\n";
            A::example();
        }
    }// A 类没有对象,这将输出
    //   I am the original function A::example().<br>
    A::example();// 建立一个 B 类的对象
    $b = new B;// 这将输出
    //   I am the redefined function B::example().<br>
    //   I am the original function A::example().<br>
    $b->example();
    ?>