Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 2
    A workaround to this is the use of factory methods to instantiate objects and chain from there, e.g. MailClass::create('mail')->setFrom('X'). The downside in PHP versions before 5.3 is that they have no late static binding, i.e. static methods would refer to the class where they were defined. Additionally, static method calls are slow. Commented Sep 29, 2010 at 13:55
  • @Archimedix - valid point, and late static binding will be a godsend (once I can enforce that my libraries are always run against 5.3+) Commented Sep 29, 2010 at 14:00
  • I always use an abstract registry with static methods to instantiate objects and store them within an array so my out come would be Registry::Use("Mail")->X()->Y->Z(); where initialization is done at within the method: Registry::Use("Mail") Commented Sep 29, 2010 at 14:09
  • You CAN chain directly from the class instantiation in PHP 5.4+ see: [stackoverflow.com/a/2188690/3200414] Commented Jan 9, 2017 at 0:51