PHPackages                             aklump/phpswap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aklump/phpswap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aklump/phpswap
==============

0.0.13(12mo ago)022914BSD-3-ClausePHPPHP &gt;=5.5

Since Sep 11Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/aklump/phpswap)[ Packagist](https://packagist.org/packages/aklump/phpswap)[ RSS](/packages/aklump-phpswap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (14)Used By (14)

PHP Swap
========

[](#php-swap)

Summary
-------

[](#summary)

Provides a means to easily execute code with PHP versions other than the default. This was first built to run PhpUnit tests within Composer projects across multiple PHP versions. See example below.

Quick Start
-----------

[](#quick-start)

This simple code example should give you an idea of how this works.

```
mkdir foo
cd foo
composer init
composer require aklump/phpswap
php -v
./vendor/bin/phpswap use 5.6 "php -v; echo"
./vendor/bin/phpswap use 8.1 "php -v; echo"
```

What It Does
------------

[](#what-it-does)

- Temporarily modifies `$PATH` with a different PHP version binary.
- If *composer.json* is present, runs `composer update` so that dependencies appropriate for the swapped PHP version get installed.
- Runs the given executable, which can be a command or a script path.
- Lastly, if necessary, runs `composer update` with the original PHP to restore the Composer dependencies.

What PHP Versions Are Supported?
--------------------------------

[](#what-php-versions-are-supported)

To see the available versions, which will echo those versions provided by MAMP you can use the `show` command.

```
./vendor/bin/phpswap show
```

Dependencies
------------

[](#dependencies)

- [MAMP](https://www.mamp.info/en/mamp)

Getting Started
---------------

[](#getting-started)

1. Ensure you have MAMP installed.
2. Download all PHP versions using MAMP that you hope to swap.
3. `composer require aklump/phpswap` in your project.
4. Use `vendor/bin/phpswap show` to see what versions are available.
5. `./phpswap list` to see all available commands.

Examples with PhpUnit
---------------------

[](#examples-with-phpunit)

Here is a pattern you can use to run PhpUnit under PHP 7.1, 7.4 and 8.1.

- Given you have installed phpunit in your project with Composer
- And you run your tests using `./vendor/bin/phpunit -c phpunit.xml`
- Then you can implement PhpSwap in the following way:
- See also Controller File Example further down.

```
./vendor/bin/phpswap use 7.1 './vendor/bin/phpunit -c phpunit.xml'
./vendor/bin/phpswap use 7.4 './vendor/bin/phpunit -c phpunit.xml'
./vendor/bin/phpswap use 8.1 './vendor/bin/phpunit -c phpunit.xml'
```

CLI Options
-----------

[](#cli-options)

### `-v`

[](#-v)

In verbose mode you will see the Composer output.

### `--working-dir`

[](#--working-dir)

This sets the working directory from which your script is called. This is optional.

Troubleshooting
---------------

[](#troubleshooting)

During execution, a file called *composer.lock.phpswap* is temporarily created in your project. It contains a copy of the *composer.lock* file that was in your project before the swap. This file is used to refresh *composer.lock* at the end of a swap. In some error situations this file may not be deleted. Use the snippet below to recover.

You may also see "Composer detected issues in your platform:" after a swap executed. The same applies here, try the snippet below.

```
mv composer.lock.phpswap composer.lock;composer update
```

Controller File Example
-----------------------

[](#controller-file-example)

Here is a complete snippet for controlling tests. Save as *bin/run\_unit\_tests.sh* and call it like this: `bin/run_unit_tests.sh -v`. You may leave off the verbose `-v` flag unless troubleshooting.

```
#!/usr/bin/env bash
s="${BASH_SOURCE[0]}";[[ "$s" ]] || s="${(%):-%N}";while [ -h "$s" ];do d="$(cd -P "$(dirname "$s")" && pwd)";s="$(readlink "$s")";[[ $s != /* ]] && s="$d/$s";done;__DIR__=$(cd -P "$(dirname "$s")" && pwd)

cd "$__DIR__/.."

verbose=''
if [[ "${*}" == *'-v'* ]]; then
  verbose='-v'
fi
./vendor/bin/phpswap use 7.3 $verbose './vendor/bin/phpunit -c tests_unit/phpunit.xml'
./vendor/bin/phpswap use 7.4 $verbose './vendor/bin/phpunit -c tests_unit/phpunit.xml'
./vendor/bin/phpswap use 8.0 $verbose './vendor/bin/phpunit -c tests_unit/phpunit.xml'
./vendor/bin/phpswap use 8.1 $verbose './vendor/bin/phpunit -c tests_unit/phpunit.xml'
./vendor/bin/phpswap use 8.2 $verbose './vendor/bin/phpunit -c tests_unit/phpunit.xml'
```

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance50

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~39 days

Total

13

Last Release

364d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79476f3b82f9c766433c7eb401cbcfc636cd5d5ccf2b2e6b50ea81d1de6c2730?d=identicon)[aklump](/maintainers/aklump)

---

Top Contributors

[![aklump](https://avatars.githubusercontent.com/u/425737?v=4)](https://github.com/aklump "aklump (56 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aklump-phpswap/health.svg)

```
[![Health](https://phpackages.com/badges/aklump-phpswap/health.svg)](https://phpackages.com/packages/aklump-phpswap)
```

###  Alternatives

[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

4743.5k10](/packages/phel-lang-phel-lang)[symfony/ai-bundle

Integration bundle for Symfony AI components

30282.3k6](/packages/symfony-ai-bundle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
