Blog Sections Open

Hardening PHx: Placeholder Cleanup and Safer then/else Parsing

A technical PHx article about safer placeholder cleanup and avoiding premature parsing of then/else branches.

This PHx deep-dive is one of the more historically valuable parser topics from the community archive because it moves past template syntax and into engine behavior. The focus was on making PHx less destructive when unresolved placeholders or complex then/else branches were involved.

Problem 1: placeholder cleanup that was too aggressive

When snippets such as Jot or Reflect left unresolved placeholders behind, PHx could remove more than it should during cleanup. The proposed fix was to narrow placeholder removal so PHx would only strip unresolved tags that appeared inside parameter contexts instead of wiping broad placeholder patterns too early.

Problem 2: parsing both then and else branches

Another issue was that PHx could parse code inside both branches before the condition resolved. That meant cached chunks or snippets inside then and else could both be touched even though only one branch should survive.

The historical solution was to delay that parsing step so only the winning branch got executed.

Why this matters

This is exactly the kind of low-level parser tuning that explains why PHx was both powerful and fragile. It also helps explain the later shift toward smaller helpers and clearer render paths: once you start patching regex behavior inside a parser extension, you are already paying a maintenance cost.

Related code

Historical PHx patch gist

Related posts

PHx 2.2.0 for Evolution CMS: Better Placeholders and PHP 5.3 Support
Do You Really Need PHx in an Evolution CMS Project?

Newer post

Choosing the Right Date Field for Sorting Resources in Evolution CMS

A clear best-practices article about why `createdon`, `publishedon`, and `pub_date` are not interchangeable.

Older post

Fixing TinyMCE Upload Errors After a Hosting Move by Correcting MODX_BASE_PATH

A migration-related TinyMCE upload failure caused by a broken base path after moving an Evolution CMS site.