How to throw a PHP Exception from Go
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 11.3k
- Forks
- 488
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 11
Description
I've been reading https://frankenphp.dev/docs/extensions/ page and I am trying to build a PHP extension entirely in Go. So far, the type mapping for strings and integers works great.
However, I can't find a way to make a function throw a PHP Exception when something goes wrong in the Go logic.
If a Go function fails, I want to handle it with a standard PHP try/catch block:
try {
repeat_this('hello', -1);
} catch (Exception $e) {
echo "Caught: " . $e->getMessage(); // Should show the error from Go
}
Is there a way to trigger a PHP exception from within the Go function?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the extensions documentation at frankenphp.dev/docs/extensions/ and trace how Go extension functions report failures to PHP. Document the supported path, if one exists, and verify that the example's PHP try/catch behavior is accurately described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, php
- Domain
- backend, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100