Skip to content

Commit

Permalink
Replace environment variables with the display_exception option
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed May 31, 2024
1 parent a1e14d3 commit 3446a88
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/phpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ void release_argv(uint32_t argc, zval *argv);
} // namespace python
struct Options {
bool numeric_as_object;
bool display_exception;
};
} // namespace phpy

Expand Down
2 changes: 2 additions & 0 deletions src/php/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ ZEND_METHOD(PyCore, setOptions) {

if ((opt = phpy::php::array_get(options, ZEND_STRL("numeric_as_object")))) {
phpy_options.numeric_as_object = zend_is_true(opt);
} else if ((opt = phpy::php::array_get(options, ZEND_STRL("display_exception")))) {
phpy_options.display_exception = zend_is_true(opt);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/python/callable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ static PyObject *Callable_call(ZendCallable *self, PyObject *args, PyObject *kwd
zval retval;
zend_result result = phpy::php::call_fn(NULL, &self->callable, &retval, argc, argv);
if (result == FAILURE) {
if (EG(exception) && phpy::php::env_equals(ZEND_STRL("phpy_display_exception"), ZEND_STRL("on"))) {
if (EG(exception) && phpy_options.display_exception) {
zend_exception_error(EG(exception), E_ERROR);
zend_clear_exception();
}
PyErr_Format(PyExc_RuntimeError, "Function call failed");
return NULL;
Expand Down

0 comments on commit 3446a88

Please sign in to comment.