]> granicus.if.org Git - php/commitdiff
Assert that symbol table is available in compact()
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Aug 2019 12:24:31 +0000 (14:24 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Aug 2019 12:25:48 +0000 (14:25 +0200)
I believe NULL here is no longer possible due to the dynamic call
check. A similar assumption already exists in the extract()
implementation.

ext/standard/array.c
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h

index fcb0f21bcdb1d57c1c463580738357f47276995f..84f19c46f73f94747feba2646ac8ae6fb9cbe20f 100644 (file)
@@ -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.
index 146e14d51d0d33c2380d36f8c9fa893e89735ddf..ea1d99f1d58571ebeff48544c6458d8a0da315eb 100644 (file)
@@ -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) {}
index 19ebcc10104eec52d3cc9855a4ae5c29da7257a7..4ca84cf4c89ebb71d2ac325c179a4aab811f3844 100644 (file)
@@ -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()