Getting startedDocumentation

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.

src/Shelf.phnyou write
namespace App;

final class Shelf<T>
{
    private list<T> $items = [];

    add(T $item): void {
        $this->items[] = $item;
    }

    all(): list<T> => $this->items;
}
.src/Shelf.phpphn build writes
<?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

Use the tools

Take part

Contributing lists the repositories, how a change is made and where to report a bug.