Use PHP Tokens as Rule Replacement Sources Without Speculative Execution

A Rule can use a PHP Token as its replacement source, but QCDR 1.1.05 does not execute that PHP merely because the Rule exists on the page. QCDR first verifies the request targeting and finds real eligible occurrences of the Rule search value.

Only selected matches reach Token resolution. This prevents a PHP Token—especially one configured for Every occurrence—from running speculatively on pages where the Rule ultimately replaces nothing.

What QCDR Checks Before PHP Can Run

Normal Rule processing first confirms the Rule is available at the current Effective Tier, that Rule processing is enabled, and that the request qualifies for the Rule's page, extension, audience, schedule, IP, and technical-condition targeting. QCDR then searches the eligible rendered-output regions for the Rule's configured search value.

If there are no eligible matches, the PHP Token used as the replacement source is not resolved. No PHP execution is needed because there is nothing to replace.

Execution Happens Per Selected Match

After QCDR finds the full match set, the Rule's occurrence controls choose which matches are actually eligible for replacement. QCDR resolves the replacement Token inside that selected-match loop.

  • Once per page request: the first selected match executes the PHP. QCDR caches the raw PHP output for that Token for the rest of the current Joomla request, while nested QCDR placeholders in the cached output are still resolved for each occurrence.
  • Every occurrence: each selected Rule match can execute the PHP again independently.
  • No selected match: no replacement-source PHP execution occurs.

Both Rule and Token Availability Still Matter

A Rule that depends on a Token is intentionally left unapplied when Token Live Processing is disabled during normal live processing. The same non-destructive behavior applies when the selected PHP Token is unavailable for the request, plan-locked, disabled, outside its own targeting, or fails with hidden PHP errors.

In those cases, QCDR preserves the administrator-authored matched content instead of replacing it with a blank result.

Preview Uses the Same Match-First Principle

Authorized Rule Preview can test a saved Rule privately even when the normal live switches are off. The preview request still discovers actual matches before it resolves a Token-backed replacement. A PHP Token used by the selected Rule can therefore execute during Preview when a real selected match exists.

Safe Test Procedure

  1. Keep the Rule saved as Draft or Disabled while testing.
  2. Target a controlled frontend URL where you know the search value is present.
  3. Open Preview Rule and confirm Rule Health shows the targeting gates and search text as qualifying.
  4. Verify the preview replacement and the PHP Token output.
  5. Repeat on a page where the search value is absent. The Rule should show no eligible match and the replacement-source PHP should not be needed for that Rule.
  6. If the PHP has side effects, perform this test on staging or use deliberately non-destructive test code.

Why This Boundary Matters

PHP Tokens are trusted server-side code. Deferring them until a genuine replacement is selected reduces unnecessary execution and makes Every occurrence mean what it says: execute for real replacement occurrences, not for speculative checks.


Community Discussion

Want to compare workflows, share practical tips, or discuss how you use this QCDR feature? Visit the QC Dynamic Replacer Community. For private support, bug reports, account-specific issues, or feature requests, use the QuantaCade support system.