Phel compiles to PHP, so every PHP debugging function is available through the php/ prefix. Reach for these alongside Phel's built-in REPL helpers.
Native var_dump()#
Any PHP function via php/ prefix:
;; Dumping a definition by its name
(def v (+ 2 2))
(php/var_dump v)
;; OUTPUT:
;; int(4);; Directly dumping the result of a function
(php/var_dump (+ 3 3))
;; OUTPUT:
;; int(6)
(php/die) halts execution so you can inspect at leisure.
When to use var_dump()#
- Quick debugging: no setup
- Inspect PHP objects: internal structure
- Type checks: verify type conversions
- Legacy code: existing PHP codebases
Symfony VarDumper: dump() & dd()#
Use Symfony VarDumper. Install via composer under require-dev:
"require-dev": {
"symfony/var-dumper": "^7.4"
},
dump() a definition or result:
(php/dump (+ 4 4))
;; OUTPUT:
8
dd() dumps and halts:
(php/dd (+ 5 5))
;; OUTPUT:
10Why Symfony VarDumper?#
Beautiful output: syntax highlighting, collapsible nested structures, better formatting than var_dump().
Rich info: object properties/methods, resource types, circular references.
Web-friendly: HTML output, dark mode, copy-to-clipboard.
Best practices#
;; Use dump() during development
(defn process-user [user]
(php/dump user) ; Inspect without stopping
(-> user
(validate)
(save)))
;; Use dd() to stop and inspect
(defn debug-pipeline [data]
(-> data
(transform)
(php/dd) ; Stop here and inspect
(save))) ; Never reachedCheck the evaluated PHP#
Keep generated temp PHP files for debugging. Useful when an error references /private/var/folders/.../T/__phelV2KvGD that no longer exists. See docs.
<?php # phel-config-local.php
return (require __DIR__ . '/phel-config.php')
->withKeepGeneratedTempFiles(true)
;
TIP: Add to
.gitignoreto control dev config without touching the global one.
Inspecting compiled PHP#
After withKeepGeneratedTempFiles(true):
- Find the files in
/tmp/or system temp dir. - Read the PHP to see how Phel compiles.
- Understand errors by matching line numbers.
- Learn the compiler by seeing optimization patterns.
Example:
;; Your Phel code
(defn greet [name]
(str "Hello, " name "!"))
Generated PHP:
<?php
// Generated PHP (simplified)
function greet($name) {
return "Hello, " . $name . "!";
}
Useful for:
- Debugging compiler issues
- Understanding performance
- Learning Phel internals
- Reporting bugs with concrete examples
PHP error reporting#
Detailed errors in development:
<?php # phel-config-local.php
error_reporting(E_ALL);
ini_set('display_errors', '1');
return (require __DIR__ . '/phel-config.php')
->withKeepGeneratedTempFiles(true)
;
Catches:
- Type errors
- Undefined variables
- Deprecated calls
- Warnings and notices
Next steps#
- Phel debug helpers for native debugging
- XDebug for step-through debugging
- Config docs for more dev settings