Effects of method chaining

OrataWefe

New Member
I know the benefits of chaining within PHP but lets say we have this following situation\[code\]$Mail = new MailClass("mail") ->SetFrom("X") ->SetTo("X") ->SetSubject("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->AddRecipient("X") ->Send();\[/code\]Are there any issues with returning and reusing the object over and over again, issues such as speed or failure to follow best PractisesAlso a good read on this if your new to Fluent-Interface's: Martin Fowler on Fluent-InterfacesI Fully understand that it doesn't have to be programmed this way, and can be handled like so:\[code\]$Mail = new MailClass("mail");$Mail->AddRecipien( array(/*.....*/));$Mail->SetFrom("X");$Mail->SetTo("X");$Mail->SetSubject("X");$Mail->Send();\[/code\]but lets say I have an object like so:\[code\]$Order = new Order() ->With(22,'TAL') ->With(38,'HPK')->Skippable() ->With(2,'LGV') ->Priority();\[/code\]Note the \[code\]->With(38,'HPK')->Skippable()\[/code\], This is perfect example of a Pro for this type of programming
 
Back
Top