Skip to content

Commit

Permalink
Merge branch 'PHP-7.1'
Browse files Browse the repository at this point in the history
* PHP-7.1:
  get_defined_functions additional parameter to exclude disabled functions
  news entry for PR php#1312
  • Loading branch information
krakjoe committed Jan 4, 2017
2 parents 8bc2155 + 6c91640 commit d838285
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ PHP NEWS

- Standard:
. Add subject to mail log. (tomsommer)
. Fixed bug #31875 (get_defined_functions additional param to exclude
disabled functions). (willianveiga)

- XML:
. Moved utf8_encode() and utf8_decode() to the Standard extension. (Andrea)
Expand Down
16 changes: 13 additions & 3 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1966,13 +1966,22 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
zend_function *func = Z_PTR_P(zv);
zval *internal_ar = va_arg(args, zval *),
*user_ar = va_arg(args, zval *);
zend_bool *exclude_disabled = va_arg(args, zend_bool *);

if (hash_key->key == NULL || ZSTR_VAL(hash_key->key)[0] == 0) {
return 0;
}

if (func->type == ZEND_INTERNAL_FUNCTION) {
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
char *disable_functions = INI_STR("disable_functions");

if ((*exclude_disabled == 1) && (disable_functions != NULL)) {
if (strstr(disable_functions, func->common.function_name->val) == NULL) {
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
}
} else {
add_next_index_str(internal_ar, zend_string_copy(hash_key->key));
}
} else if (func->type == ZEND_USER_FUNCTION) {
add_next_index_str(user_ar, zend_string_copy(hash_key->key));
}
Expand All @@ -1986,16 +1995,17 @@ static int copy_function_name(zval *zv, int num_args, va_list args, zend_hash_ke
ZEND_FUNCTION(get_defined_functions)
{
zval internal, user;
zend_bool exclude_disabled = 0;

if (zend_parse_parameters_none() == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &exclude_disabled) == FAILURE) {
return;
}

array_init(&internal);
array_init(&user);
array_init(return_value);

zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 2, &internal, &user);
zend_hash_apply_with_arguments(EG(function_table), copy_function_name, 3, &internal, &user, &exclude_disabled);

zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
Expand Down
23 changes: 23 additions & 0 deletions tests/basic/bug31875.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Bug #31875 get_defined_functions() should not list disabled functions
--CREDITS--
Willian Gustavo Veiga <[email protected]>
--INI--
disable_functions=dl
--FILE--
<?php
$disabled_function = 'dl';

$functions = get_defined_functions();
var_dump(in_array($disabled_function, $functions['internal']));

$functions = get_defined_functions(false);
var_dump(in_array($disabled_function, $functions['internal']));

$functions = get_defined_functions(true);
var_dump(in_array($disabled_function, $functions['internal']));
?>
--EXPECTF--
bool(true)
bool(true)
bool(false)

0 comments on commit d838285

Please sign in to comment.