Skip to content

Commit ee16d99

Browse files
committed
Remove create_function()
Deprecated in PHP 7.2 as part of https://wiki.php.net/rfc/deprecations_php_7_2.
1 parent 734c305 commit ee16d99

18 files changed

+6
-413
lines changed

Zend/tests/anonymous_func_001.phpt

Lines changed: 0 additions & 54 deletions
This file was deleted.

Zend/tests/anonymous_func_002.phpt

Lines changed: 0 additions & 19 deletions
This file was deleted.

Zend/tests/anonymous_func_003.phpt

Lines changed: 0 additions & 16 deletions
This file was deleted.

Zend/tests/bug48693.phpt

Lines changed: 0 additions & 52 deletions
This file was deleted.

Zend/tests/closure_025.phpt

Lines changed: 0 additions & 13 deletions
This file was deleted.

Zend/tests/exception_012.phpt

Lines changed: 0 additions & 23 deletions
This file was deleted.

Zend/tests/instanceof_001.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var_dump($a instanceof stdClass);
88

99
var_dump(new stdCLass instanceof stdClass);
1010

11-
$b = create_function('', 'return new stdClass;');
11+
$b = function() { return new stdClass; };
1212
var_dump($b() instanceof stdClass);
1313

1414
$c = array(new stdClass);
@@ -22,8 +22,6 @@ var_dump("$a" instanceof stdClass);
2222
--EXPECTF--
2323
bool(true)
2424
bool(true)
25-
26-
Deprecated: Function create_function() is deprecated in %s on line %d
2725
bool(true)
2826
bool(true)
2927
bool(false)

Zend/zend_builtin_functions.c

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ static ZEND_FUNCTION(get_declared_traits);
6767
static ZEND_FUNCTION(get_declared_interfaces);
6868
static ZEND_FUNCTION(get_defined_functions);
6969
static ZEND_FUNCTION(get_defined_vars);
70-
static ZEND_FUNCTION(create_function);
7170
static ZEND_FUNCTION(get_resource_type);
7271
static ZEND_FUNCTION(get_resources);
7372
static ZEND_FUNCTION(get_loaded_extensions);
@@ -197,11 +196,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_functions, 0, 0, 0)
197196
ZEND_ARG_INFO(0, exclude_disabled)
198197
ZEND_END_ARG_INFO()
199198

200-
ZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2)
201-
ZEND_ARG_INFO(0, args)
202-
ZEND_ARG_INFO(0, code)
203-
ZEND_END_ARG_INFO()
204-
205199
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1)
206200
ZEND_ARG_INFO(0, res)
207201
ZEND_END_ARG_INFO()
@@ -276,7 +270,6 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
276270
ZEND_FE(get_declared_interfaces, arginfo_zend__void)
277271
ZEND_FE(get_defined_functions, arginfo_get_defined_functions)
278272
ZEND_FE(get_defined_vars, arginfo_zend__void)
279-
ZEND_DEP_FE(create_function, arginfo_create_function)
280273
ZEND_FE(get_resource_type, arginfo_get_resource_type)
281274
ZEND_FE(get_resources, arginfo_get_resources)
282275
ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions)
@@ -1895,78 +1888,6 @@ ZEND_FUNCTION(get_defined_vars)
18951888
}
18961889
/* }}} */
18971890

1898-
#define LAMBDA_TEMP_FUNCNAME "__lambda_func"
1899-
/* {{{ proto string create_function(string args, string code)
1900-
Creates an anonymous function, and returns its name (funny, eh?) */
1901-
ZEND_FUNCTION(create_function)
1902-
{
1903-
zend_string *function_name;
1904-
char *eval_code, *function_args, *function_code;
1905-
size_t eval_code_length, function_args_len, function_code_len;
1906-
int retval;
1907-
char *eval_name;
1908-
1909-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &function_args, &function_args_len, &function_code, &function_code_len) == FAILURE) {
1910-
return;
1911-
}
1912-
1913-
eval_code = (char *) emalloc(sizeof("function " LAMBDA_TEMP_FUNCNAME)
1914-
+function_args_len
1915-
+2 /* for the args parentheses */
1916-
+2 /* for the curly braces */
1917-
+function_code_len);
1918-
1919-
eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME "(") - 1;
1920-
memcpy(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(", eval_code_length);
1921-
1922-
memcpy(eval_code + eval_code_length, function_args, function_args_len);
1923-
eval_code_length += function_args_len;
1924-
1925-
eval_code[eval_code_length++] = ')';
1926-
eval_code[eval_code_length++] = '{';
1927-
1928-
memcpy(eval_code + eval_code_length, function_code, function_code_len);
1929-
eval_code_length += function_code_len;
1930-
1931-
eval_code[eval_code_length++] = '}';
1932-
eval_code[eval_code_length] = '\0';
1933-
1934-
eval_name = zend_make_compiled_string_description("runtime-created function");
1935-
retval = zend_eval_stringl(eval_code, eval_code_length, NULL, eval_name);
1936-
efree(eval_code);
1937-
efree(eval_name);
1938-
1939-
if (retval==SUCCESS) {
1940-
zend_op_array *func;
1941-
HashTable *static_variables;
1942-
1943-
func = zend_hash_str_find_ptr(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
1944-
if (!func) {
1945-
zend_error_noreturn(E_CORE_ERROR, "Unexpected inconsistency in create_function()");
1946-
RETURN_FALSE;
1947-
}
1948-
if (func->refcount) {
1949-
(*func->refcount)++;
1950-
}
1951-
static_variables = func->static_variables;
1952-
func->static_variables = NULL;
1953-
zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
1954-
func->static_variables = static_variables;
1955-
1956-
function_name = zend_string_alloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG, 0);
1957-
ZSTR_VAL(function_name)[0] = '\0';
1958-
1959-
do {
1960-
ZSTR_LEN(function_name) = snprintf(ZSTR_VAL(function_name) + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)) + 1;
1961-
} while (zend_hash_add_ptr(EG(function_table), function_name, func) == NULL);
1962-
RETURN_NEW_STR(function_name);
1963-
} else {
1964-
zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1);
1965-
RETURN_FALSE;
1966-
}
1967-
}
1968-
/* }}} */
1969-
19701891
#if ZEND_DEBUG && defined(ZTS)
19711892
ZEND_FUNCTION(zend_thread_id)
19721893
{

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ static const func_info_t func_infos[] = {
258258
I1("get_declared_interfaces", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
259259
F1("get_defined_functions", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY),
260260
I1("get_defined_vars", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF),
261-
FN("create_function", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
262261
F1("get_resource_type", MAY_BE_NULL | MAY_BE_STRING),
263262
F1("get_defined_constants", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_FALSE | MAY_BE_ARRAY_OF_TRUE | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_DOUBLE | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_RESOURCE | MAY_BE_ARRAY_OF_ARRAY),
264263
F0("debug_print_backtrace", MAY_BE_NULL),

ext/opcache/tests/bug68252.phpt

Lines changed: 0 additions & 21 deletions
This file was deleted.

ext/standard/tests/general_functions/print_r.phpt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,7 @@ $misc_values = array (
271271
/* calling check_printr() to display miscelleneous data using print_r() */
272272
check_printr($misc_values);
273273

274-
/* checking print_r() on functions */
275-
echo "\n*** Testing print_r() on anonymous functions ***\n";
276-
$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
277-
echo "New anonymous function: $newfunc\n";
278-
print_r( $newfunc(2, 3) );
279-
/* creating anonymous function dynamically */
280-
print_r( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
281-
282-
echo "\n\n*** Testing error conditions ***\n";
274+
echo "\n*** Testing error conditions ***\n";
283275
//passing zero argument
284276
var_dump( print_r() );
285277

@@ -1715,14 +1707,6 @@ Array
17151707

17161708

17171709

1718-
*** Testing print_r() on anonymous functions ***
1719-
1720-
Deprecated: Function create_function() is deprecated in %s on line %d
1721-
New anonymous function: lambda_1
1722-
2 * 3 = 6
1723-
Deprecated: Function create_function() is deprecated in %s on line %d
1724-
lambda_2
1725-
17261710
*** Testing error conditions ***
17271711

17281712
Warning: print_r() expects at least 1 parameter, 0 given in %s on line %d

0 commit comments

Comments
 (0)