How this stuff works?
$object->foo1()->foo2()->foo3();
I’m working in Magento php framework. In Magento functions are called as sequence.But, I don’t understand how it works.Can anyone explain.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, PHP will get a pointer to the
foo1method from the$objectvariable. It calls this method, which then returns another object. This second object (we shall call it$object2) has a methodfoo2(), which is also called.foo2()returns another object ($object3), which has a methodfoo3(), which returns whatever it likes.In some cases,
$object,$object2and$object3are just pointers to the same object. This means that you can keep calling methods on the same class in a nice sequence.You can achieve this quite easily: