Skip to content

Commit a47f170

Browse files
committed
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.
1 parent 99c57b3 commit a47f170

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

ext/standard/array.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ PHP_FUNCTION(extract)
24692469
}
24702470

24712471
symbol_table = zend_rebuild_symbol_table();
2472+
ZEND_ASSERT(symbol_table && "A symbol table should always be available here");
24722473

24732474
if (extract_refs) {
24742475
switch (extract_type) {
@@ -2566,7 +2567,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
25662567
}
25672568
/* }}} */
25682569

2569-
/* {{{ proto array|null compact(mixed var_names [, mixed ...])
2570+
/* {{{ proto array compact(mixed var_names [, mixed ...])
25702571
Creates a hash containing variables and their values */
25712572
PHP_FUNCTION(compact)
25722573
{
@@ -2583,9 +2584,7 @@ PHP_FUNCTION(compact)
25832584
}
25842585

25852586
symbol_table = zend_rebuild_symbol_table();
2586-
if (UNEXPECTED(symbol_table == NULL)) {
2587-
return;
2588-
}
2587+
ZEND_ASSERT(symbol_table && "A symbol table should always be available here");
25892588

25902589
/* compact() is probably most used with a single array of var_names
25912590
or multiple string names, rather than a combination of both.

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function array_search($needle, array $haystack, bool $strict = false) {}
141141
/** @prefer-ref $arg */
142142
function extract(array &$arg, int $extract_type = EXTR_OVERWRITE, string $prefix = ""): ?int {}
143143

144-
function compact($var_name, ...$var_names): ?array {}
144+
function compact($var_name, ...$var_names): array {}
145145

146146
/** @return array|false */
147147
function array_fill(int $start_key, int $num, $val) {}

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_extract, 0, 1, IS_LONG, 1)
156156
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
157157
ZEND_END_ARG_INFO()
158158

159-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 1)
159+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 0)
160160
ZEND_ARG_INFO(0, var_name)
161161
ZEND_ARG_VARIADIC_INFO(0, var_names)
162162
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)