Skip to content

Commit

Permalink
Fix is_callable() can not access internal private callable on PHP8 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
twose authored Nov 20, 2020
1 parent 21290cf commit ca218a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions ext-src/php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,15 @@ static sw_inline zend_bool sw_zend_is_callable(zval *callable, int check_flags,
return ret;
}

static sw_inline zend_bool sw_zend_is_callable_ex(zval *zcallable, zval *zobject, uint check_flags, char **callable_name, size_t *callable_name_len, zend_fcall_info_cache *fci_cache, char **error)
static sw_inline zend_bool sw_zend_is_callable_at_frame(zval *zcallable, zval *zobject, zend_execute_data *frame, uint check_flags, char **callable_name, size_t *callable_name_len, zend_fcall_info_cache *fci_cache, char **error)
{
zend_string *name;
zend_bool ret = zend_is_callable_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, check_flags, &name, fci_cache, error);
zend_bool ret;
#if PHP_VERSION_ID < 80000
ret = zend_is_callable_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, check_flags, &name, fci_cache, error);
#else
ret = zend_is_callable_at_frame(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, frame, check_flags, &name, fci_cache, error);
#endif
if (callable_name)
{
*callable_name = estrndup(ZSTR_VAL(name), ZSTR_LEN(name));
Expand All @@ -924,6 +929,11 @@ static sw_inline zend_bool sw_zend_is_callable_ex(zval *zcallable, zval *zobject
return ret;
}

static sw_inline zend_bool sw_zend_is_callable_ex(zval *zcallable, zval *zobject, uint check_flags, char **callable_name, size_t *callable_name_len, zend_fcall_info_cache *fci_cache, char **error)
{
return sw_zend_is_callable_at_frame(zcallable, zobject, NULL, check_flags, callable_name, callable_name_len, fci_cache, error);
}

/* this API can work well when retval is NULL */
static sw_inline int sw_zend_call_function_ex(zval *function_name, zend_fcall_info_cache *fci_cache, uint32_t param_count, zval *params, zval *retval)
{
Expand Down
2 changes: 1 addition & 1 deletion ext-src/swoole_http_server_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static PHP_METHOD(swoole_http_server_coro, start) {
zend_fcall_info_cache fci_cache;
zval zcallback;
ZVAL_STRING(&zcallback, "onAccept");
if (!sw_zend_is_callable_ex(&zcallback, ZEND_THIS, 0, &func_name, nullptr, &fci_cache, nullptr)) {
if (!sw_zend_is_callable_at_frame(&zcallback, ZEND_THIS, execute_data, 0, &func_name, nullptr, &fci_cache, nullptr)) {
php_swoole_fatal_error(E_CORE_ERROR, "function '%s' is not callable", func_name);
return;
}
Expand Down

0 comments on commit ca218a5

Please sign in to comment.