Hi,
Looking to a proper way to use "zend_register_functions" in MINIT
function (to be able to register various list, from different sources) I
found the "zend_register_functions" which is available in public API and
used in
- zend_register_module_ex() with module.functions
- php_module_startup() with sapi_module.additional_functions
Issue: reflection is broken for this registered functions.
We have in sapi/cli/php_cli.c
static const zend_function_entry additional_functions[] = {
ZEND_FE(dl, arginfo_dl)
PHP_FE(cli_set_process_title, arginfo_cli_set_process_title)
PHP_FE(cli_get_process_title, arginfo_cli_get_process_title)
{NULL, NULL, NULL}
};
$ php --re standard | grep process_title
=> no result
$ php -r 'print_r(get_extension_funcs("standard"));' | grep proces
=> no result
Any idea how to properly register functions and keep reflection reliable ?
Remi.
Iterating on CG(function_table) instead of module.functions is a
possible fix.
Attached: rewrite of get_extension_funcs
Test:
foreach(get_loaded_extensions() as $ext) {
$a[$ext] = get_extension_funcs($ext);
}
print_r($a);
$ diff old new
-
[528] => dl
-
[529] => cli_set_process_title
-
[530] => cli_get_process_title
Minor change, when a extension replace a core function,
Ex: memprof use
const zend_function_entry memprof_function_overrides[] = {
PHP_FALIAS(memory_get_peak_usage, memprof_memory_get_peak_usage,
arginfo_memprof_memory_get_usage)
PHP_FALIAS(memory_get_usage, memprof_memory_get_usage,
arginfo_memprof_memory_get_usage)
PHP_FE_END /* Must be the last line in
memprof_function_overrides[] */
};
With this patch the "memory_get_peak_usage" will be reported as part of
"memprof" extension instead of "standard", but I think this seems also
correct (another effect of the bug)
Comments ?
Remi.
Attached: rewrite of _extension_string and getFunctions.
Test 1: php --re standard
$diff -u old new
- Function [ internal:standard function dl ] {
-
- Parameters [1] {
-
Parameter #0 [ <required> $extension_filename ]
-
}
- }
- Function [ internal:standard function cli_set_process_title ] {
-
- Parameters [1] {
-
Parameter #0 [ <required> $title ]
-
}
- }
- Function [ internal:standard function cli_get_process_title ] {
-
- Parameters [0] {
-
}
- }
Test 2:
$r=new ReflectionExtension('standard')
print_r($r->getFunctions());
- [dl] => ReflectionFunction Object
-
(
-
[name] => dl
-
)
- [cli_set_process_title] => ReflectionFunction Object
-
(
-
[name] => cli_set_process_title
-
)
- [cli_get_process_title] => ReflectionFunction Object
-
(
-
[name] => cli_get_process_title
-
)
Remi.