php / php/frankenphp

How to throw a PHP Exception from Go

Open
#2,273 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.