Skip to content

Conversation

@datamweb
Copy link
Contributor

@datamweb datamweb commented Jan 1, 2026

Description
This PR enhances the DebugToolbar's detection logic to support third-party libraries that bypass the framework's Response object (e.g., Dompdf).

Currently, CodeIgniter relies solely on its internal Response object to decide whether to inject the toolbar. However, many libraries output content directly using native PHP header() and echo. In these cases, the Toolbar assumes the content is HTML and injects itself, which is often undesirable for binary streams.

I've implemented a Native State Awareness mechanism in Toolbar::prepare(). The toolbar now acts as a secondary guard, validating the environment's actual state before injection.

This issue has been raised before by several community members on the forum. At the time, we were unable to clearly identify the root cause, as the behavior only manifests when third-party libraries bypass the framework’s abstraction layer and interact directly with native PHP output mechanisms.

After revisiting the problem with a deeper analysis of the runtime behavior, I was able to trace the issue to a mismatch between the framework’s assumed response state and the actual native PHP state. Based on that insight, this PR introduces a more resilient detection mechanism that addresses not only the originally reported cases, but also a broader class of similar issues.

See: https://forum.codeigniter.com/showthread.php?tid=82461

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@datamweb datamweb marked this pull request as draft January 1, 2026 08:03
@michalsn
Copy link
Member

michalsn commented Jan 1, 2026

I haven't investigated this problem, but my first impression is that we should rather make it as simple as possible.

We can check for $response->hasHeader('Debugbar-Skip') response header and then skip the Toolbar.

We can add a new method to the Response class:

public function withoutDebugbar()
{
    if (CI_DEBUG) {
        $this->setHeader('Debugbar-Skip', 'true');
    }

    return $this;
}

This won't resolve anything automatically, but it will provide developers with the tools to remove the Debugbar when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants