GoPHP is an implementation of the PHP language specification written in the Go programming language.
The goals of the project are:
- Deep dive into the PHP language syntax and the internals of its mode of operation
- Gain more experience in writing lexers, parser and interpreter
- Very long-term goal: Implement as many parts of the standard library and language features as needed to run a simple Laravel application 😓
More documentation:
Usage of ./goPHP:
-h Show help
-dev Run in developer mode.
-S string Run with built-in web server. <addr>:<port>
-t string Specify document root <docroot> for built-in web server.
-f string Parse and execute <file>.
Parse file:
cat index.php | ./goPHP
or ./goPHP -f index.php
Run web server:
./goPHP -S localhost:8080
- Document root is current working directory
./goPHP -S localhost:8080 -dev
- Web server in developer mode
./goPHP -S localhost:8080 -t /srv/www/html
- Document root is /srv/www/html
Compile and run
go run ./...
Build executable
go build -o . ./...
Run all tests
go test -v ./...
See test coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
There are a lot of test cases in the source repository for PHP under the folder tests.
In order to test the GoPHP implementation against this cases the binary goPhpTester
can be used.
Usage:
./goPhpTester <list of directory or phpt-file>
Examples:
./goPhpTester php-src/tests
./goPhpTester php-src/tests/basic/001.phpt
For some part of this project, the following resources were used as a guide, inspiration, or concept:
- PHP Language Specification
- YouTube playlist Build a Custom Scripting Language In Typescript by tylerlaceby
- Book Crafting Interpreters by Robert Nystorm
- Book Writing An Interpreter In Go by Thorsten Ball