From: Nikita Popov Date: Mon, 26 Aug 2019 12:24:31 +0000 (+0200) Subject: Assert that symbol table is available in compact() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a47f170a7562d40d2f675600c641c616c2ebc592;p=php Assert that symbol table is available in compact() I believe NULL here is no longer possible due to the dynamic call check. A similar assumption already exists in the extract() implementation. --- diff --git a/ext/standard/array.c b/ext/standard/array.c index fcb0f21bcd..84f19c46f7 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2469,6 +2469,7 @@ PHP_FUNCTION(extract) } symbol_table = zend_rebuild_symbol_table(); + ZEND_ASSERT(symbol_table && "A symbol table should always be available here"); if (extract_refs) { switch (extract_type) { @@ -2566,7 +2567,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu } /* }}} */ -/* {{{ proto array|null compact(mixed var_names [, mixed ...]) +/* {{{ proto array compact(mixed var_names [, mixed ...]) Creates a hash containing variables and their values */ PHP_FUNCTION(compact) { @@ -2583,9 +2584,7 @@ PHP_FUNCTION(compact) } symbol_table = zend_rebuild_symbol_table(); - if (UNEXPECTED(symbol_table == NULL)) { - return; - } + ZEND_ASSERT(symbol_table && "A symbol table should always be available here"); /* compact() is probably most used with a single array of var_names or multiple string names, rather than a combination of both. diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 146e14d51d..ea1d99f1d5 100644 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -141,7 +141,7 @@ function array_search($needle, array $haystack, bool $strict = false) {} /** @prefer-ref $arg */ function extract(array &$arg, int $extract_type = EXTR_OVERWRITE, string $prefix = ""): ?int {} -function compact($var_name, ...$var_names): ?array {} +function compact($var_name, ...$var_names): array {} /** @return array|false */ function array_fill(int $start_key, int $num, $val) {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 19ebcc1010..4ca84cf4c8 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -156,7 +156,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_extract, 0, 1, IS_LONG, 1) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 0) ZEND_ARG_INFO(0, var_name) ZEND_ARG_VARIADIC_INFO(0, var_names) ZEND_END_ARG_INFO()