PHPackages                             ramsey/composer-repl - 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. [CLI &amp; Console](/categories/cli)
4. /
5. ramsey/composer-repl

ActiveComposer-plugin[CLI &amp; Console](/categories/cli)

ramsey/composer-repl
====================

A REPL for PHP built into Composer.

1.5.1(1y ago)105111.1k↑56.1%320MITPHP ^8.1CI passing

Since Aug 26Pushed 1y ago5 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (17)Used By (20)

ramsey/composer-repl
====================

[](#ramseycomposer-repl)

 **A REPL for PHP built into Composer.**

 [![Source Code](https://camo.githubusercontent.com/a954c700b608e751ca6b07dd69a282a03dae9468ae1274a460dcda8f49d02995/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d72616d7365792f636f6d706f7365722d2d7265706c2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/ramsey/composer-repl) [![Download Package](https://camo.githubusercontent.com/0ac602ee998c9e63c1390bc6a04932f0d2fd163b30376272fcd48ddd107912af/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616d7365792f636f6d706f7365722d7265706c2e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/ramsey/composer-repl) [![PHP Programming Language](https://camo.githubusercontent.com/542b2dc94cf65b3c583984b9bd5727b53135107f515a619ef16d8017709ada9e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616d7365792f636f6d706f7365722d7265706c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License](https://camo.githubusercontent.com/a77ba6fc94d7337129a20bcccb9b1ab615691bb06007617a46251bfb03362d77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72616d7365792f636f6d706f7365722d7265706c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6461726b6379616e)](https://github.com/ramsey/composer-repl/blob/main/LICENSE) [![Build Status](https://camo.githubusercontent.com/e127952496bcd699fa46c14cb01f4560387b6c2a15ec94c8f3159c7955f0242b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616d7365792f636f6d706f7365722d7265706c2d6c69622f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/ramsey/composer-repl-lib/actions/workflows/continuous-integration.yml) [![Codecov Code Coverage](https://camo.githubusercontent.com/afa53b4ede62e2d5581f9bd865d4a6a58c4b227f75e796da94d7c6c6b96b145d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f72616d7365792f636f6d706f7365722d7265706c2d6c69623f6c6162656c3d636f6465636f76266c6f676f3d636f6465636f76267374796c653d666c61742d737175617265)](https://codecov.io/gh/ramsey/composer-repl-lib)

About
-----

[](#about)

This [Composer](https://getcomposer.org) plugin provides the `composer repl`command.

REPL stands for *read-eval-print loop*. It's a language shell that reads user input, evaluates the input using a programming language (in this case, PHP), and prints the output to the screen. Then, it returns to the read state (that's the *loop* part).

[PsySH](https://psysh.org) is the REPL providing the magic behind ramsey/composer-repl. PsySH is a language shell for PHP. It's similar to [irb](https://github.com/ruby/irb) for Ruby, [IPython](https://ipython.org) for Python, and [JShell](https://docs.oracle.com/javase/9/tools/jshell.htm) for Java. In addition to acting as a language shell, PsySH can also function as an interactive debugger and development console. [Laravel Tinker](https://github.com/laravel/tinker), [Drush](https://www.drush.org)for Drupal, [WP-CLI shell](https://github.com/wp-cli/shell-command)for WordPress, [CakePHP console](https://book.cakephp.org/3/en/console-and-shells/repl.html), and [Yii shell](https://github.com/yiisoft/yii2-shell) are a few of the projects using PsySH.

Tip

You may use this REPL without the Composer plugin functionality by requiring [ramsey/composer-repl-lib](https://github.com/ramsey/composer-repl-lib) instead.

This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Installation
------------

[](#installation)

Install this package as a development dependency using [Composer](https://getcomposer.org).

```
composer require --dev ramsey/composer-repl
```

Usage
-----

[](#usage)

Open your terminal and type `composer repl`. You may also type `composer shell`, if you prefer.

You'll see something similar to this:

```
Psy Shell v0.12.7 (PHP 8.4.4 — cli) by Justin Hileman
------------------------------------------------------------------------
Welcome to the development console (REPL).
To learn more about what you can do in PsySH, type `help`.
------------------------------------------------------------------------
>>>

```

While in the dev console, you can do cool things like this:

```
>>> $hello = 'Hello, world'
=> "Hello, world"

>>> echo $hello
Hello, world

>>> foreach ([1, 2, 3] as $x) echo $x . "\n"
1
2
3

>>> $date = new DateTimeImmutable();
=> DateTimeImmutable @1598393282 {#6953
     date: 2020-08-25 22:08:02.643076 UTC (+00:00),
   }

>>> $getDate = fn (DateTimeInterface $dt): DateTimeInterface => $dt;
=> Closure(DateTimeInterface $dt): DateTimeInterface {#6964 …3}

>>> t assertInstanceOf(DateTimeInterface::class, $date);
Test passed!

>>> t assertSame($date, $getDate($date))
Test passed!

>>> phpunit

PHPUnit 12.0.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.4
Configuration: /path/to/ramsey/conventional-commits/phpunit.xml.dist

...............................................................  63 / 221 ( 28%)
............................................................... 126 / 221 ( 57%)
............................................................... 189 / 221 ( 85%)
................................                                221 / 221 (100%)

Time: 00:00.064, Memory: 12.00 MB

OK (221 tests, 484 assertions)
```

Important

✨🐘 This implementation of PsySH has Super ElePHPant Powers. 🐘✨

Environment Bootstrapping
-------------------------

[](#environment-bootstrapping)

The power of this REPL comes in its ability to act as a tool in your local development environment. So, you might want to load parts of your environment (i.e., configuration, objects, etc.), so you can access these from within the REPL.

You can do this by specifying any number of PHP scripts to include in `composer.json`, like this:

```
{
    "extra": {
        "ramsey/composer-repl": {
            "includes": [
                "repl.php",
                "tests/bootstrap.php"
            ]
        }
    }
}
```

Any variables set or configuration loaded from these scripts is available to use from within the REPL.

For example, if `repl.php` contains:

```
