Skip to content

Commit

Permalink
Support exit() function in PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Nov 23, 2024
1 parent b2791e0 commit c2ba746
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

#include <Zend/zend_closures.h>

#ifndef ZEND_EXIT
#include "zend.h"
#include <Zend/zend_attributes.h>
#include <Zend/zend_builtin_functions_arginfo.h>
#endif /* ZEND_EXIT */

ZEND_EXTERN_MODULE_GLOBALS(uopz);

static zend_function* uopz_copy_function(zend_class_entry *scope, zend_string *name, zend_object *closure, zend_long flags) { /* {{{ */
Expand Down Expand Up @@ -403,6 +409,20 @@ zend_bool uopz_get_static(zend_class_entry *clazz, zend_string *function, zval *
return 1;
} /* }}} */

void uopz_exit_function(INTERNAL_FUNCTION_PARAMETERS) { /* {{{ */
zend_string *str = NULL;
zend_long code = 0;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_LONG(str, code)
ZEND_PARSE_PARAMETERS_END();

if (UOPZ(exit)) {
zif_exit(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
} /* }}} */

#endif /* UOPZ_FUNCTION */

/*
Expand Down
3 changes: 3 additions & 0 deletions src/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

#define ZEND_ACC_UOPZ (1<<30)

#include "zend.h"

zend_bool uopz_add_function(zend_class_entry *clazz, zend_string *name, zval *closure, zend_long flags, zend_bool all);
zend_bool uopz_del_function(zend_class_entry *clazz, zend_string *name, zend_bool all);

void uopz_flags(zend_class_entry *clazz, zend_string *name, zend_long flags, zval *return_value);
zend_bool uopz_set_static(zend_class_entry *clazz, zend_string *function, zval *statics);
zend_bool uopz_get_static(zend_class_entry *clazz, zend_string *function, zval *return_value);
void uopz_exit_function(INTERNAL_FUNCTION_PARAMETERS);

#endif /* UOPZ_FUNCTION_H */

Expand Down
8 changes: 8 additions & 0 deletions uopz.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ static PHP_MINIT_FUNCTION(uopz)
uopz_executors_init();
uopz_handlers_init();

/* #ifndef ZEND_EXIT */
do {
zend_function *php_function_entry = zend_hash_str_find_ptr(CG(function_table), "exit", sizeof("exit") - 1);
ZEND_ASSERT(php_function_entry);
php_function_entry->internal_function.handler = uopz_exit_function;
} while (0);
/* #endif */

return SUCCESS;
}
/* }}} */
Expand Down

0 comments on commit c2ba746

Please sign in to comment.