duanbu1998 2012-04-04 13:48 采纳率: 0%
浏览 10

php对象运算符 - >没有实例?

I have the following code in script I implement and it does work correctly, just want to understand:

   $variable1 = function1();  // function1 is a class method, it’s file included per require_once 
   $ variable1 -> function2(); // function2 is a class method, it’s file included per require_once

Isn’t -> here an object operator? But there is no initialized instance save in $variable1.

Help appreciated

  • 写回答

1条回答 默认 最新

  • doulun5683 2012-04-04 13:49
    关注

    That just means that function1() returns an object.

    Hence you can use that object and it's functions.

    Example:

    class Test {
        function function2(){
            echo "Hi";
        }
    }
    
    function function1(){ return new Test; }
    
    
    //SO:
    
    $variable1 = function1();  
    $variable1->function2(); 
    
    评论

报告相同问题?