[UPHPU] Fluent interfaces

John David Anderson uphpu at johndavidanderson.net
Tue May 8 16:52:07 MDT 2007


> I personally like the way jQuery does it because you never get null  
> back.
> You always at least get an empty jQuery object back.
> And I think one of jQuery's strong points is doing a lot with very few
> lines of code

Doing a lot with very few lines of code often translates into code  
that is harder to maintain and read. I can see how it could be useful  
in places, but the maintenance of code written this way keeps me for  
using it much.

$criteria = array(
	'and' => array(
  		'order.date > 2001-01-01',
		'order.status == 'foo'
	)
	'or' => array(
		'order.justdoit == true'
	)
);
$orders->search($criteria);

With some sort of array or object based syntax, I can have dynamic  
criteria. It is much easier to build arrays/objects dynamically than  
dynamic chains.

I don't think it's hard to architect a class that does this sort of  
thing that never returns null either. PHP is pretty tolerant of null  
cases (unlike Java, dear goodness) anyway.

-- John


More information about the UPHPU mailing list