dansan/php-backport
Dev tool to backport PHP source code for older runtimes (e.g., PHP 7.2+ features down to PHP 7.0). Configure directories to port, run a script on a *_bp branch, commit/push, then require the backported dev branch in Composer.
Alpha/Beta/Gamma dependency chain). This is a validated technical debt mitigation strategy for monolithic or constrained environments where migration is infeasible.nikic/php-parser (mature, battle-tested) for AST manipulation.collect(), Str::, Facades) may not backport cleanly without custom rules.backport.php per project (not plug-and-play).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| False Positives | High | Test backported code against PHP 7.0 before merging into master_bp. |
| Syntax Ambiguity | Medium | Extend BackPort\Client with Laravel-specific visitor rules. |
| Dependency Bloat | Low | Use --dev flag (as shown in README) to avoid runtime overhead. |
| Merge Conflicts | High | Automate conflict resolution (e.g., Git hooks) for _bp branches. |
| Testing Gaps | Critical | Add PHP 7.0 CI checks (e.g., GitHub Actions with php:7.0-cli). |
array_key_first(), match(), attributes?)_bp branches be synced with master? (Automated? Manual?)nikic/php-parser be extended to handle Laravel’s syntax? (e.g., Blade templates, Eloquent methods).Alpha eventually upgrades to PHP 7.2+?php-compat): More limited but less invasive.array_merge with spread operator, nullsafe).Alpha’s usage).dansan/php-backport to composer.json (--dev).backport.php with:
$client
->setDirsToPort([__DIR__.'/app', __DIR__.'/src'])
->addComposerJsonReplacement('/"laravel\/framework": "[^"]+"/', '"laravel/framework": "v7.0.0"')
->execute();
_bp branches on master merges._bp branch pushes.Alpha.BACKPORTING.md with:
create_function, call_user_method).mysql_* functions).app()->bind() syntax if using PHP 7.2+ features.collect()->when() with if blocks.::class constants in some cases).PHPUnit with php:7.0 Docker image.phpstan-baseline for backported code.Alpha’s dependency chain (Beta → Gamma)._bp branch management (e.g., GitHub Actions)._bp branches as Alpha upgrades.backport.php as new PHP 7.2+ features are added to master._bp branches may diverge from master; require manual syncs.nikic/php-parser for breaking changes.Debugging Complexity:
master. Requires:
master_bp vs. master).array_key_first() to array_search()").| Environment | PHP Version | Backported? | Notes |
|---|---|---|---|
Alpha (prod) |
7.0 | Yes | Uses _bp branches. |
Beta (dev) |
7.2+ | No | master branch. |
Gamma (CI) |
7.0/7.2+ | Conditional | Test both branches. |
Community Risks:
master instead of _bp._bp branches.backport.php templates across projects._bp branches._bp branches.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Backported code breaks PHP 7.0 | Alpha deployment fails |
Pre-merge PHP 7. |
How can I help you explore Laravel packages today?