Generic Declarative Expression Builder in PHP Generic Declarative Expression Builder in PHP ajax ajax

Generic Declarative Expression Builder in PHP


A word of caution. These types of generic expression builders are commonly thought of as excellent solutions to a variety of user problems. The thinking tends to go along these lines:

  • The user wants all these different reports
  • There's no way we're giving them SQL access (even if they could understand it)
  • We don't have time to write all these custom reports
  • Therefore, I'll make an easy way for them to write queries without having to know specific syntax, tables and fields.

This is not necessarily a bad idea, but what we have found at my company is that non-techie users have surprising difficulty understanding and building expressions more complex than a group of ANDS or a group of ORS. This is hard for us programmers to grasp, as most of us probably had an intuitive understanding of boolean logic even before we learned to program.

I would recommend that you not try to give them complete flexibility to create whatever expression they want, and instead you put together a UI that lets you the programmer define something more complicated on the back-end but gives the user simple choices on the front-end. This is easier said than done, obviously.

Remember - sometimes the difficulty for end users isn't the fact that they don't know the right syntax to express their idea in. More often it's because they don't even know how to formulate their thoughts in an unambiguous way, even if they were provided an easy way to do so.

NOTE: I'm not saying the end users are always morons - just that their minds may work differently from us crazy developers.


This isn't exactly a component, but you might take a look at the Conditions tab of the Shopping Cart rule builder in Magento for a solid PHP implementation of this type of functionality. It is customized towards e-commerce, so it is not a generic database overlay, but it does have a great condition builder interface.


I think this is a very interesting idea. Are you planning on working on this project for personal use or through work?

If you are planning on working on this project personally, maybe you should write it yourself and turn it into an open source project. It looks like there is already some interest in this area and it would be a good learning experience.

Otherwise, I can see how a company could find value in something like this. It would give the programmers another utility that could help them do their job a little bit easier and pay dividends in the long run.

Either way, this project is win. You will learn alot, and create something that other people find useful.