staabm/side-effects-detector
Detects side effects in PHP code so you can safely eval or decide to isolate execution. Classifies effects (stdout, exit, includes/scope pollution, etc.) and flags unknown/userland calls as “maybe”. Used by PHPUnit to speed up PHPT tests.
Start by installing the package via Composer: composer require staabm/side-effects-detector. Begin with the basic use case—detecting if a snippet of PHP code (e.g., from a test case or user input) has observable side effects before evaluating it with eval(). The simplest intro is analyzing PHPUnit’s PHPT test snippets: load code, run getSideEffects(), and check the returned list of SideEffect::CONSTANT values. For example, SideEffect::STANDARD_OUTPUT for echo/printf, SideEffect::PROCESS_EXIT for exit(), or SideEffect::SCOPE_POLLUTION for include/global usage.
PROCESS_EXIT, SCOPE_POLLUTION) while allowing harmless ones (STANDARD_OUTPUT captured via ob_start).in_array($effect, $allowedEffects) to support custom policies (e.g., allow STANDARD_OUTPUT but not EXTENSION_LOAD).null return means unknown side-effect (e.g., userland function calls) — treat as SideEffect::MAYBE and default to safest behavior (e.g., subprocess).trigger_error as unknown (1.0.4+) or vprintf/printf as STANDARD_OUTPUT (1.0.2/1.0.3+), but relies on internal function mapping.fwrite(STDOUT, ...), header() calls), so combine STANDARD_OUTPUT detection with defensive ob_start() and warn users about limitations.include, global, class/func autoloading) can’t be fully neutralized in-process—subprocess isolation remains the only reliable way.How can I help you explore Laravel packages today?