Convert PHP source code to Go by AST walking
Go to file
mappu 8533e72047 doc: update progress in README 2020-04-05 19:26:49 +12:00
fixtures stmt/class: support super() calls 2020-04-05 19:11:05 +12:00
vendor vendor: commit github.com/z7zmey/php-parser v0.7.0 (MIT license) 2020-04-05 16:36:06 +12:00
.gitignore fixtures: exclude *.parse.json from git 2020-04-05 16:37:34 +12:00
README.md doc: update progress in README 2020-04-05 19:26:49 +12:00
fixtures_test.go test: ensure fixtures are processed in order 2020-04-05 17:11:20 +12:00
go.mod initial commit 2020-04-05 16:35:44 +12:00
go.sum initial commit 2020-04-05 16:35:44 +12:00
literal.go initial commit 2020-04-05 16:35:44 +12:00
main.go stmt: track conversion state in a struct 2020-04-05 18:45:14 +12:00
node.go stmt/class: support `self::` calling our renamed static methods 2020-04-05 19:26:36 +12:00
scope.go initial commit 2020-04-05 16:35:44 +12:00

README.md

php2go

Convert PHP source code to Go by AST walking.

The goal is to produce idiomatic, maintainable Go code as part of a one-off conversion. This is not generally possible for highly dynamic PHP code, that may require manual fixups.

Progress

[X] Convert some small programs [X] Error handling - [X] All functions return (type, error) - [X] Convert throw to err return - [ ] Elide error return for functions that cannot throw - ?? Could be a standalone Go refactoring tool - [ ] Non-leaf function calls need to check + bubble errors - [ ] Behaviour of function calls in rvalue cases where err cannot be checked [ ] Comprehensive coverage of all AST node types - [ ] Node - [ ] Stmt - [ ] Expr - [X] Binary - [ ] Scalar [X] Array handling - [X] Infer whether to use slice/map for PHP array - [ ] Infer whether map use should be order-preserving [ ] Multi-file programs - [ ] Include/Require [ ] Namespaces [ ] Generators [ ] Numbered break/continue [ ] Goto [ ] Comma operator [ ] isset/unset [ ] instanceof [ ] try/catch/finally [ ] Abandon upon sight of eval / extract / ... [ ] Closures - [ ] Handle value/reference captures [ ] Sort callbacks - [ ] Transparent conversion to sort.Slice [X] Convert top-level calls to init()/main() - Currently always init [ ] Class/object transformations - [X] Convert new X constructor calls to NewX - [X] Visibility - [ ] Call mangled function name at call sites - PHP variable names are case-sensitive, function names are case-insensitive - [X] Static methods - [X] Inheritance partial - [ ] Interfaces - [X] super - [X] Need to track current conversion state through into function generator, to select the concrete parent - [X] parent:: - [X] self:: - [ ] static:: - [ ] Traits / use - [ ] Abstract methods [ ] Type inference - [ ] Convert known PHP typenames to Go equivalents - [ ] Parse extra types from phpdoc blocks [ ] Infer whether to declare variable (var / :=) or reuse (=) - [ ] Track current visibility scope [ ] Library/environment transformations - [ ] Standard library transformations - [ ] Track golang package imports - [ ] Handle conflicts between golang stdlib packages / local variable names - [ ] PHP Superglobal transformations - [ ] $_SERVER['argv'] to os.Args - [ ] $_GET['name'] to r.FormValue('name') - [ ] Common 3rd party package transformations to popular equivalents (optional) - [ ] Guzzle - [ ] AWS SDK - [ ] PHPUnit -> Go Test - [ ] Replace Composer/PSR-4 autoloading with Go imports [X] Variadic function parameters [ ] Preserve comments [ ] Preserve rough line spacing [ ] Convert wordpress / mediawiki / symfony - [ ] Option to convert with preset=cli, preset=web, webroot path - [ ] Option to generate built-in web server [ ] Generate source maps [ ] Command-line tool option to go run