Standard PHP serialization fails when you need to store complex objects in a database AND query them with SQL. Enter Flatterizor.

The Problem

Imagine you have a user object with nested permissions:

$user = [
    'name' => 'John',
    'permissions' => [
        'can_read' => true,
        'can_write' => false,
        'can_delete' => true
    ]
];

Using serialize() produces output like:

a:2:{s:4:"name";s:4:"John";s:11:"permissions";a:3:{...}}

Now try to write a SQL query to find all users with can_write = true. Nearly impossible.

The Solution

Flatterizor converts complex objects into a normalized structure:

// Input
$user = ['name' => 'John', 'permissions' => ['can_write' => true]];

// Output: flattened key-value pairs
[
    ['path' => 'name', 'value' => 'John'],
    ['path' => 'permissions.can_write', 'value' => true]
]

Database Implementation

Create a table with path/value columns:

CREATE TABLE user_meta (
    user_id INT,
    name VARCHAR(255),  -- the property path
    val TEXT            -- the property value
);

Now you can easily query:

SELECT DISTINCT user_id FROM user_meta
WHERE name = 'permissions.can_write' AND val = '1';

Real-World Use Case

This library emerged from WordPress development needs. I had forms with ~30 fields that needed to be stored as post metadata while remaining searchable.

Instead of creating 30 separate meta keys, Flatterizor handles the complexity automatically while keeping everything queryable.

Get Started

Check out the GitHub repository for documentation and examples.