A powerful, interactive REPL (Read-Eval-Print Loop) console for Phunkie - bringing functional programming to PHP.
- Interactive REPL: Evaluate PHP expressions and see results immediately
- Functional Programming: Full access to Phunkie's functional programming constructs
- Type Inspection: Query types and kinds of expressions with
:typeand:kindcommands - Import System: Import functions from Phunkie standard library on-the-fly
- Syntax Highlighting: Color-coded output for better readability
- Multi-line Support: Write complex expressions across multiple lines
- Rich Output: Formatted display of complex data structures
- PHP 8.2, 8.3, or 8.4
- Composer
composer require phunkie/consoleOr install globally:
composer global require phunkie/consoleStart the REPL:
php vendor/bin/phunkieOr if installed globally:
$ phunkie
Welcome to phunkie console.
Type in expressions to have them evaluated.
phunkie >phunkie > 1 + 2
$var0: Int = 3
phunkie > ImmList(1, 2, 3, 4, 5)->map(fn($x) => $x * 2)
$var1: ImmList = List(2, 4, 6, 8, 10)
phunkie > Some(42)->map(fn($x) => $x * 2)
$var2: Option = Some(84):quitor:exit- Exit the REPL:type <expression>- Show the type of an expression:kind <type>- Show the kind of a type:import <function(s)>- Import a function from the Phunkie standard library:load <filepath>- Load a PHP file silently (all definitions become available in the session):help- Show help information
phunkie > Some(42)->getOrElse(0)
$var0: Int = 42
phunkie > None()->getOrElse(0)
$var1: Int = 0
phunkie > Some(10)->flatMap(fn($x) => Some($x * 2))
$var2: Option = Some(20)phunkie > $list = ImmList(1, 2, 3, 4, 5)
$var0: ImmList = List(1, 2, 3, 4, 5)
phunkie > $list->filter(fn($x) => $x > 2)
$var1: ImmList = List(3, 4, 5)
phunkie > $list->reduce(fn($acc, $x) => $acc + $x, 0)
$var2: Int = 15The REPL automatically detects incomplete expressions and prompts for continuation:
phunkie > function double($x) {
phunkie { return $x * 2;
phunkie { }
imported function double()
phunkie > double(21)
$var0: Int = 42phunkie > :type ImmList(1, 2, 3)
ImmList
phunkie > :kind Option
* -> *
phunkie > :import strlen
imported function strlen()
phunkie > strlen("hello")
$var0: Int = 5
phunkie > :load helpers.php
// file helpers.php loaded
phunkie > // Now all functions and classes from helpers.php are availableEnable colors with the -c flag:
php vendor/bin/phunkie -cRun all tests:
./vendor/bin/phpunit
./vendor/bin/behatRun version-specific tests:
./bin/run-behat-tests.shThe project maintains comprehensive test coverage:
- Unit Tests: Testing individual components with PHPUnit
- Acceptance Tests: End-to-end REPL functionality with Behat
- Cross-version Testing: Automated testing across PHP 8.2, 8.3, and 8.4
# Static analysis
./vendor/bin/phpstan analyze
# Code style
./vendor/bin/php-cs-fixer fixThe console is built with a modular architecture:
- Parser: Uses nikic/php-parser for PHP syntax analysis
- Evaluator: Safe evaluation of PHP expressions
- Session: Stateful session management using the State monad
- Display: Formatted output with type information
- Terminal: Readline integration for command history
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.