Getting started
Documentation
Install Phaenon, learn the language, use the compiler and its tools, and bring Phaenon into a PHP project. For the 0.7.2 compiler.
Phaenon is a typed dialect of PHP that compiles to the PHP you would have written by hand. You write .phn files, PHP without the opening tag, in which generics, lists, maps, tuples, bytes and throws are part of the language. The compiler, phn, checks the whole program as strictly as PHPStan at level max, then writes plain PHP 8.5 or 8.6 with the docblocks PHPStan and PhpStorm read. The output depends on nothing but PHP: no runtime library, no extension, nothing extra to deploy.
namespace App;
final class Shelf<T>
{
private list<T> $items = [];
add(T $item): void {
$this->items[] = $item;
}
all(): list<T> => $this->items;
}<?php
/* @generated by phaenon from Shelf.phn */
declare(strict_types=1);
namespace App;
/**
* @template T
*/
final class Shelf
{
/**
* @var list<T>
*/
private array $items = [];
/**
* @param T $item
*/
public function add(mixed $item): void
{
$this->items[] = $item;
}
/**
* @return list<T>
*/
public function all(): array
{
return $this->items;
}
}These pages describe the 0.7.2 compiler. Phaenon is pre-alpha: the language and the command line still change between releases, and the design says where they are going.
Try it on a project
- Install the compiler, through Composer or as one binary.
- A first project: from an empty directory to a class written in Phaenon, compiled, tested with PHPUnit and analysed with PHPStan.
- Migrate a PHP project with
phn migrate, all at once or a directory at a time.
Learn the language
- Phaenon for PHP developers: what the language adds to PHP, and what it leaves as it is.
- Generics: type parameters on classes, interfaces and functions, what you would write as
@templatein a docblock. - Lists, maps and tuples: arrays with a type.
- Named shapes and type aliases: names for the types you repeat.
- Text and bytes: binary data that the checker tells apart from text.
- Methods, functions and closures: declarations without
function, and bodies of one expression. throwsandnothrow: the exceptions a function lets escape.- Type tests and narrowing: how the checker follows PHP's own tests.
- Pipes and partial application:
|>and?for any target. - What Phaenon refuses: the PHP it does not compile.
Use the tools
- The
phncommand: every command and option. phaenon.json: roots, target, exclusions.- The type checker: what
phn checkreports, and how it compares with PHPStan. - Formatting and fixers:
phn fmt, and php-cs-fixer or Rector throughphn fix. - Line maps and debugging: positions in the compiled PHP traced back to the
.phn. - Editors: PhpStorm, VS Code and the language server.
- Continuous integration: the checks to run on every change.
- Publishing a library: a package written in Phaenon, for projects with or without
phn. - Local development: the loop of editing, checking and building on your machine.
Take part
Contributing lists the repositories, how a change is made and where to report a bug.