Sky Blue Sofa Blog Chainable: Make your PHP classes more fluent - Sky Blue Sofa Blog

Chainable: Make your PHP classes more fluent

Posted by Dave Rogers // October 3, 2016 // in Blog // 0 Comments

Broad_chain_closeup.jpg

Programming in PHP has come a long way from the dark ages of procedural code. Even so, there are ways to make it even easier to read and create.

Take this example from Wikipedia:

$employee = (new Employee())
->setName('Tom')
->setSurname('Smith')
->setSalary('100');

That seems easy enough, but with Chainable, it can be even simpler:

$employee = Employee::setName('Tom')
->setSurname('Smith')
->setSalary('100');
While it's not a huge change, in a larger application, every little bit helps. Let me know what you think.

About the Author

Dave Rogers

Dave is the founder of Sky Blue Sofa Web Design. He enjoys working out, spending time with his wife and dogs and programming. He grew up and currently resides in the Illinois Quad Cities. You can find his personal blog at strength/reliance.com.

View Profile »

Comments

You must be logged in to leave a reply. Login »