0

Sometimes I see things like this:

<?php echo $this->getLayout()->createBlock("menupro/menu")->setGroup_id(5)->setTemplate("menupro/menupro.phtml")->toHtml(); ?>

I was wondering whether this is a good practise?

Julian S
  • 361
  • 3
  • 13
  • 2
    Fluent interface can be very easy to read, though not typically when it's all on one line; but does have potential drawbacks if any of the methods throws an exception – Mark Baker Apr 13 '15 at 11:45

1 Answers1

1

This is a rather subjective question, I personally am all for it. You can make your code a lot more readable. Check out this link: Effects of method chaining

The major drawback is that you must return the object. You may not return any other value as you’re only allowed to return $this.

Community
  • 1
  • 1
iosifv
  • 1,153
  • 1
  • 10
  • 26