phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

Maintainers

Package info

github.com/phel-lang/phel-lang

Homepage

pkg:composer/phel-lang/phel-lang

Fund package maintenance!

chemaclass.com/sponsor

Statistics

Installs: 4 383

Dependents: 18

Suggesters: 0

Stars: 503

Open Issues: 0

v0.38.0 2026-05-16 18:05 UTC

README

Phel logo

GitHub Build Status PHPStan level 6 Psalm level 1 Psalm Type-coverage Status

Packagist Version Packagist Downloads PHP Version Required License Ask DeepWiki

Lisp for PHP — macros, persistent data structures, REPL.

Example

(ns my.example)

(defn greet [name] 
  (str "Hello, " name "!"))

(println (greet "Phel"))
;; => Hello, Phel!
More examples →

Data pipeline

(def users
  [{:name "Ada" :age 36}
   {:name "Bob" :age 17}
   {:name "Cam" :age 41}])

(->> users
     (filter #(>= (:age %) 18))
     (map :name)
     sort)
;; => ["Ada" "Cam"]

HTTP response

(ns app (:require phel.http :as h))

(def req (h/request-from-globals))

(h/emit-response
  (h/response-from-map
    {:status 200
     :headers {"Content-Type" "text/plain"}
     :body (str "Hello " (:uri req))}))

Macros

(defmacro unless [pred & body]
  `(if (not ~pred)
     (do ~@body)))

(unless (zero? 1)
  (println "not zero"))
;; => not zero

(unless false (println "ok"))
;; => ok

PHP interop

(ns app)

(def now (php/new \DateTime))
(.format now "Y-m-d")
;; => "2026-04-20"

(def epoch (php/new \DateTime "1970-01-01"))
(.-days (.diff now epoch))
;; => 20564

Getting Started

composer require phel-lang/phel-lang
./vendor/bin/phel init                     # add `--minimal` for a single-file layout

Scaffolds phel-config.php, src/phel/main.phel, tests/phel/main_test.phel.

./vendor/bin/phel run src/phel/main.phel   # run
./vendor/bin/phel test                     # tests
./vendor/bin/phel repl                     # REPL
./vendor/bin/phel build                    # compile to PHP

Eval inline or via stdin:

./vendor/bin/phel eval '(+ 1 2)'           # prints 3
echo '(println "hi")' | ./vendor/bin/phel eval -
./vendor/bin/phel eval - < script.phel

Documentation

AI Coding Agents

Skill files for Claude Code, Cursor, Codex, Gemini, Copilot, Aider: resources/agents/

./vendor/bin/phel agent-install [platform] [--all]   # install skill file for your agent