From PHP to Jennifer

Jennifer

A guide for PHP developers: what carries over, what is different, and where the familiar tools went.

by @mplx

1 / 16

What feels familiar

2 / 16

Declare before you use

$count = 0;
$count = $count + 1;
def count as int init 0;
$count = $count + 1;
3 / 16

No type juggling

ExpressionPHPJennifer
"10" == 10truefalse: a string is not an int
"5" + 16error: + needs numbers
if ($count) with an inttruthyerror: a condition is a bool
(int) "42"42convert.toInt("42")
4 / 16

Strings

$greeting = "Hello, " . $name . "!";
echo "Hello, {$name}!\n";
use io;

def name as string init "Ada";
def greeting as string init "Hello, " + $name + "!";
io.printf("Hello, {$name}!\n");
5 / 16

One array becomes two types

use io;

def names as list of string init ["Ada", "Alan"];
$names[] = "Grace";

def prices as map of string to float init {"tea": 2.5, "cake": 3.9};
$prices["coffee"] = 3.2;
for (def item in $prices) {
    io.printf("%s|pad=8 %f|prec=2\n", $item, $prices[$item]);
}
6 / 16

Objects become values

use io;

def struct Account { owner as string, balance as int };

func deposit(a as Account, amount as int) {
    $a.balance = $a.balance + $amount;
    return $a;
}

def acc as Account init Account{owner: "Ada", balance: 100};
$acc = deposit($acc, 50);
io.printf("%s has %d\n", $acc.owner, $acc.balance);
7 / 16

Numbers keep their promises

ExpressionPHPJennifer
7 / 23.53.5
intdiv(7, 2)37 // 2 gives 3
-7 % 3-12, floored like //
PHP_INT_MAX + 1a floaterror: integer overflow
8 / 16

match, as in PHP 8

use io;

def status as int init 404;
match ($status) {
    when 200 { io.printf("ok\n"); }
    when 404, 410 { io.printf("gone\n"); }
    else { io.printf("other\n"); }
}
9 / 16

Exceptions, without finally

use io;

func withdraw(balance as int, amount as int) {
    if ($amount > $balance) {
        throw Error{kind: "funds", message: "too little"};
    }
    return $balance - $amount;
}
try {
    withdraw(10, 50);
} catch (e) {
    io.printf("%s: %s\n", $e.kind, $e.message);
}
10 / 16

include, Composer and Packagist

PHPJennifer
require 'util.php';import "./util.j" as util;
extension, ext-jsonuse json; (built in)
composer require x/yjvc add "@scope/deck"
composer.lockcamcorder.lock
Packagistregistry.jennifer-lang.dev
11 / 16

The web: a server, not a request

import "web.j" as web;

func hello(ctx as web.Context) {
    def name as string init web.param($ctx, "name");
    web.text($ctx, 200, "Hello, {$name}!\n");
}

def app as web.App init web.new();
$app = web.get($app, "/hello/:name", hello);
web.run($app, "127.0.0.1:8080");
12 / 16

Databases without PDO

def db as sql.Connection init sql.open("postgres", $dsn);
def rows as sql.Rows init sql.query(
    $db, "select id, name from users where id > $1", 0);
while (sql.next($rows)) {
    io.printf("%d %s\n", sql.asInt($rows, "id"), sql.asString($rows, "name"));
}
13 / 16

Where the tools went

PHPJennifer
php -ljennifer lint
PHP-CS-Fixerjennifer fmt -w
PHPUnitjennifer test
Xdebug profilerjennifer profile
php -ajennifer repl
14 / 16

Cheat sheet

PHPJennifer
$x = 5;def x as int init 5;
$x++;, $x += 1;$x = $x + 1;
&&, ||, !and, or, not
"a" . "b""a" + "b"
count($xs), strlen($s)len($xs), len($s)
foreach ($m as $k => $v)for (def k in $m) with $m[$k]
// comment# comment
15 / 16

Where to go next

Based on Jennifer 0.26.0, November 2026.

16 / 16