Welcome to PHP Rules

PHP Rules is a lightweight, forward-chaining inference engine based on the "Rule Archetype Pattern" described in the excellent book Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML.


What is PHP Rules?

PHP Rules is a rule engine that models formal propositional logic. It allows you to separate conditional logic from source code and database triggers in a reusable package, where explicit rules can be independently defined & managed.

What are Rules?

Rules are simple statements of fact about the state of something that may be used explicitly to trigger actions.

Rules are defined & stored in text files with RUL extension. They define

RuleContexts are facts, stored in text files, databases, etc., that provide the informational context for the execution of Rule. Rules evaluate RuleContexts, returning a Boolean value that tells us whether a given set of facts conform to the defined Rule.

Rule Package Class Diagram

PHP Rule Engine In Action: View Examples of Rule Execution

In the two examples below, we load & execute Rules by fetching the Rule & RuleContext from

  1. Text files alone, and
  2. Text files with SQL statements, which are executed by the SqlFileLoaderStrategy, i.e., the results of SQL statements build Propositions & Variables.

Download & Install

Download rules.zip and unzip to your apache root directory, e.g., htdocs.


Page rendered in 0.0138 seconds