2

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 Answer 1

5

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(); 
Sign up to request clarification or add additional context in comments.

1 Comment

function1()->function2() // PHP 5.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.