deuill / go-php

PHP bindings for the Go programming language (Golang)
MIT License
930 stars 105 forks source link

Continue running the go program after exit() in PHP #59

Open thekid opened 6 years ago

thekid commented 6 years ago

Currently, if a PHP script calls exit(), not only does the script terminate, but also the GO binary running it - see #31. This pull request changes this in a backwards-compatible way* such that calls to Exec() and Eval() will return an error which can be checked for.

Example

val, err := context.Eval(script);

if err != nil {
    if exit, ok := err.(*php.ExitError); ok {
        fmt.Printf("PHP exited with exit status %d\n", exit.Status)
    } else {
        fmt.Printf("Could not execute script %s: %v", script, err)
    }
}

*: ...instead of changing the return types, or introducing any global state in context, or adding new methods. The API is modeled a bit after os/exec

deuill commented 6 years ago

Apologies for the delay in responding to these PRs, and thanks for doing the work. Looking now.