Chaining in php

Chaining has become a popular technique in javascript libraries such as jquery. The following code contains chaining:

$('table#portfolio tbody tr:odd').addClass('odd').parent() .addClass('table').find('ul').addClass('hightlight');

We can do the same with PHP very easily. All you need to do is return the current object, thus allowing chaining.

class Basic { function add(Object $object) { $this->objects[] = $object; return $this; } } $basic = new Basic; $basic->add($name)->add($email)->add($phone);

Add chaining in your PHP code to limit the lines of code that are needed for your components. Concise code is good code.