Skip to content

How to throw a PHP Exception from Go #2273

@IndraGunawan

Description

@IndraGunawan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions