# Detect if function is disabled from c ext

- Thread: https://externals.io/message/112315
- Original archive: https://news-web.php.net/php.internals/112315
- Started by vorismi3@fel.cvut.cz on 2020-11-29T22:19:31+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #112315 — vorismi3@fel.cvut.cz — 2020-11-29T22:19:31+00:00

URL: https://externals.io/message/112315#112315

How can a php function can be checked from extension if that function is
disabled or not? 

In php7.x, I used: 

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif 

#include <stdbool.h>
#include "php.h" 

bool is_php_function_disabled(const char *func_name) {
zend_internal_function *func;
if ((func = zend_hash_str_find_ptr(CG(function_table), func_name,
strlen(func_name)))) {
if (func->handler == ZEND_FN(display_disabled_function)) {
return true;
}
} 

return false;
} 

But it does not work for php8: 

In file included from /usr/local/include/php/main/php.h:35,
from .../ext/libs.c:6:
.../ext/libs.c: In function 'is_php_function_disabled':
/usr/local/include/php/Zend/zend_API.h:68:23: error:
'zif_display_disabled_function' undeclared (first use in this function)
68 | #define ZEND_FN(name) zif_##name
| ^~~~
.../ext/libs.c:237:30: note: in expansion of macro 'ZEND_FN'
237 | if (func->handler == ZEND_FN(display_disabled_function)) { 

Thanks for help in advance. 

With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,

Michael Voříšek
ČVUT FEL

---

## #112316 — Nikita Popov — 2020-11-29T22:28:28+00:00

URL: https://externals.io/message/112315#112316 · In reply to: #112315

On Sun, Nov 29, 2020 at 11:20 PM Michael Voříšek - ČVUT FEL <
vorismi3@fel.cvut.cz> wrote:

> How can a php function can be checked from extension if that function is
> disabled or not?
>
> In php7.x, I used:
>
> #ifdef HAVE_CONFIG_H
> #include "config.h"
> #endif
>
> #include <stdbool.h>
> #include "php.h"
>
> bool is_php_function_disabled(const char *func_name) {
> zend_internal_function *func;
> if ((func = zend_hash_str_find_ptr(CG(function_table), func_name,
> strlen(func_name)))) {
> if (func->handler == ZEND_FN(display_disabled_function)) {
> return true;
> }
> }
>
> return false;
> }
>
> But it does not work for php8:
>
> In file included from /usr/local/include/php/main/php.h:35,
> from .../ext/libs.c:6:
> .../ext/libs.c: In function 'is_php_function_disabled':
> /usr/local/include/php/Zend/zend_API.h:68:23: error:
> 'zif_display_disabled_function' undeclared (first use in this function)
> 68 | #define ZEND_FN(name) zif_##name
> | ^~~~
> .../ext/libs.c:237:30: note: in expansion of macro 'ZEND_FN'
> 237 | if (func->handler == ZEND_FN(display_disabled_function)) {
>
> Thanks for help in advance.
>

In PHP 8, the question is ill-posed. A disabled function is
indistinguishable from a function that does not exist. (You can of course
check the value of the ini setting, but there should be no good reason to
do so.)

Nikita
