{"id":28121149,"url":"https://github.com/i582/php2go","last_synced_at":"2025-05-14T07:44:50.013Z","repository":{"id":57559386,"uuid":"288016642","full_name":"i582/php2go","owner":"i582","description":"Simple transpiler from PHP to Go","archived":false,"fork":false,"pushed_at":"2020-08-23T22:22:48.000Z","size":558,"stargazers_count":9,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T11:58:46.962Z","etag":null,"topics":["go","php","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/i582.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-16T20:09:02.000Z","updated_at":"2023-11-23T10:07:27.000Z","dependencies_parsed_at":"2022-08-28T14:52:14.276Z","dependency_job_id":null,"html_url":"https://github.com/i582/php2go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i582%2Fphp2go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i582%2Fphp2go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i582%2Fphp2go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i582%2Fphp2go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i582","download_url":"https://codeload.github.com/i582/php2go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254097173,"owners_count":22014166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","php","transpiler"],"created_at":"2025-05-14T07:42:19.549Z","updated_at":"2025-05-14T07:44:49.997Z","avatar_url":"https://github.com/i582.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php2go\n\n*php2go* is a transpiler from a small subset of PHP to Go.\n\nThis tool is written in [Go](https://golang.org/) and uses [z7zmey/php-parser](https://github.com/z7zmey/php-parser).\n\n## Get started\n\n#### Install\n\n```\ngo get github.com/i582/php2go\n```\n\n#### CLI\n\n```\nphp2go [flags]\n```\n\n| flag | type   | description |\n| ---- | ------ | ----------- |\n| -i   | string | input file  |\n| -o   | string | output file |\n\n## What is currently supported\n\n**Types**:\n\n1. `Integer`\n2. `Float`\n3. `String`\n4. `Bool`\n5. `Null`\n\nUnion types composed of the types above are also supported.\n\n**For union types supported**:\n\n1. Comparison with any type above;\n2. Use in conditions and boolean expressions;\n3. Printing.\n\n**`is_t` functions**\n\n1. `is_int`\n2. `is_float`\n3. `is_string`\n4. `is_bool`\n5. `is_null`\n\n**Operators**\n\nSupported arithmetic operators (`+`,`-`,`*`,`/` ,`.`,`++`,`--`) and \n\nboolean (`\u003c`,`\u003e`,`\u003c=`,`\u003e=`, `\u0026\u0026`, `||`) \n\n**Arrays**\n\nArrays are supported, both regular and associative, but they **must** consist of elements of the same type and with the same type of keys.\n\nIt supports index/key access, assignment to an element and a construction like `$arr[] = Elem;`\n\n**Constructs**\n\nThe following language constructs are available:\n\n1. `if-else`\n2. `for`\n3. `while`\n4. `foreach`\n\n**Output**\n\nThe `echo` operator is supported for output.\n\n\u003e  **Currently only code in function is supported.**\n\n## TODO\n\n1. Add support for all operators;\n2. Add support for other types;\n3. Add multi-file support;\n4. And much more...\n\n## Example\n\n```php\n\u003c?php\n\nfunction Foo() {\n  // int\n  $a = 100;\n  // float\n  $b = 1.5;\n  // string\n  $c = \"Hello\";\n  // bool\n  $d = true;\n  // output\n  echo $a;\n  echo $b;\n  echo $c;\n  echo $d;\n  // if-else\n  if ($a == 100) {\n    // variable inside\n    $e = 10;\n  } else {\n    // and here, so variable should be inside\n    $e = 10;\n  }\n  // output this variable\n  echo $e;\n  // another if-else\n  if ($a == 100) {\n    // variable with int type\n    $f = 10;\n  } else {\n    // here is string\n    $f = \"10\";\n  }\n  // so $f has type int|string\n  echo $f;\n  // support only single-type array\n  $f = [1,2,3];\n  echo $f;\n  // fetch by index\n  echo $f[1];\n  // assign by index\n  $f[1] = 10;\n  echo $f;\n  // simple array\n  $g = [1,2,3];\n  echo $g;\n  // adding element\n  $g[] = 100;\n  echo $g;\n  // and associative array with single-type keys\n  $f = [\"Key1\" =\u003e 1, \"Key2\" =\u003e 2, \"Key3\" =\u003e 3];\n  echo $f;\n  // fetch by key\n  echo $f[\"Key1\"];\n  // assign by key\n  $f[\"Key1\"] = 5;\n  echo $f;\n  // while\n  $i = 0;\n  while ($i \u003c 20) {\n    echo $i;\n    $i++;\n  }\n  // for\n  for ($i = 0; $i \u003c 20; $i++) {\n    echo $i + 5;\n  }\n  $qw = 1.5;\n  // different operators\n  echo $qw + 5 - 56.56 * 6 / 56;\n}\n```\n\nOutput:\n\n```go\n// Code generated by php2go. PLEASE DO NOT EDIT.\npackage index\n\nimport (\n   \"fmt\"\n)\n\nfunc Foo() {\n\ta := 100\n\tb := 1.5\n\tc := \"Hello\"\n\td := true\n\tfmt.Print(a)\n\tfmt.Print(b)\n\tfmt.Print(c)\n\tfmt.Print(d)\n\tvar e int64\n\tvar f Var\n\tif a == 100 {\n\t\te = 10\n\t} else {\n\t\te = 10\n\t}\n\tfmt.Print(e)\n\tif a == 100 {\n\t\tf.Setint64(10)\n\t} else {\n\t\tf.Setstring(\"10\")\n\t}\n\tfmt.Print(f.String())\n\tf.SetElementTypeint64([]int64{1, 2, 3})\n\tfmt.Print(f.GetElementTypeint64())\n\tfmt.Print(f.GetElementTypeint64()[1])\n\tf.GetElementTypeint64()[1] = 10\n\tfmt.Print(f.GetElementTypeint64())\n\tg := []int64{1, 2, 3}\n\tfmt.Print(g)\n\tg = append(g, 100)\n\tfmt.Print(g)\n\tf.SetmapWithKeystringWithValueint64(map[string]int64{\"Key1\": 1, \"Key2\": 2, \"Key3\": 3})\n\tfmt.Print(f.GetmapWithKeystringWithValueint64())\n\tfmt.Print(f.GetmapWithKeystringWithValueint64()[\"Key1\"])\n\tf.GetmapWithKeystringWithValueint64()[\"Key1\"] = 5\n\tfmt.Print(f.GetmapWithKeystringWithValueint64())\n\ti := 0\n\tfor i \u003c 20 {\n\t\tfmt.Print(i)\n\t\ti++\n\t}\n\tfor i = 0; i \u003c 20; i++ {\n\t\tfmt.Print(i + 5)\n\t}\n\tqw := 1.5\n\tfmt.Print(qw + float64(5) - 56.56 * float64(6) / float64(56))\n}\n```\n\nThe `Var` structure is a container for Union types.\n\n\n\n## Contacts\n\nName: Petr Makhnev\n\nE-Mail: mr.makhneff@gmail.com\n\nTelegram: [@petr_makhnev](https://t.me/petr_makhnev)\n\nVK: [@petrmakhnev](https://vk.com/petrmakhnev)\n\n## License\n\nThis library is released under the [MIT](https://github.com/i582/component-sdl2/blob/master/LICENSE) license. For more information refer to the [LICENSE](https://github.com/i582/component-sdl2/blob/master/LICENSE) file provided with this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi582%2Fphp2go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi582%2Fphp2go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi582%2Fphp2go/lists"}