本帖最后由 keric2008 于 2013-08-26 18:33:02 编辑

解决方案 »

  1.   

    如果你非要这样做的话,那么函数就需要传参,传一个对象进来。{
    $instest = new test();
    $insobject = new object();
    $instest->test($insobject);
    }class test{
    function test($insobject){
    $insobject->hello();
    }
    }class object{
    function hello(){
    echo "hello";
    }
    }
    一般从设计的角度来说,采用继承的方式,会更好。
      

  2.   

    这与面向对象无关!
    只是个变量作用域的问题!
    class test{
        function test(){
            $insobject->hello();
        }
    }
    中 $insobject 是局部变量,并且也没有赋值。
    当然也就没有 hello 方法了
      

  3.   

    class test{
        function test(){
            global $insobject;
            $insobject->hello();
        }
    }
    这样每个函数里 都要申明不是很复杂么!!没有什么委婉一点的么
      

  4.   

    $_ENV['變量名']這玩意可以超全局使用,類似的還有:$_GLOBALS['變量名'];$_GET['變量名'];$_POST['變量名'];$_REQUEST['變量名']等
      

  5.   

    用你这方法不行。Warning: Missing argument 1 for test::test(), called in C:\wamp\www\zhebo\index.php on line 24 and defined in C:\wamp\www\zhebo\x\init.php on line 170
      

  6.   

    class test{
        function test(){
            object::hello();
        }
    }class object{
        Public static function hello(){
            echo "hello";
        }
    }