From ee16d99504f0014c3d292809da927fb622293f41 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 28 Jan 2019 12:41:36 +0100 Subject: [PATCH] Remove create_function() Deprecated in PHP 7.2 as part of https://wiki.php.net/rfc/deprecations_php_7_2. --- Zend/tests/anonymous_func_001.phpt | 54 ------------- Zend/tests/anonymous_func_002.phpt | 19 ----- Zend/tests/anonymous_func_003.phpt | 16 ---- Zend/tests/bug48693.phpt | 52 ------------ Zend/tests/closure_025.phpt | 13 --- Zend/tests/exception_012.phpt | 23 ------ Zend/tests/instanceof_001.phpt | 4 +- Zend/zend_builtin_functions.c | 79 ------------------- ext/opcache/Optimizer/zend_func_info.c | 1 - ext/opcache/tests/bug68252.phpt | 21 ----- .../tests/general_functions/print_r.phpt | 18 +---- .../general_functions/print_r_64bit.phpt | 18 +---- .../tests/general_functions/var_dump.phpt | 17 ---- .../general_functions/var_dump_64bit.phpt | 17 ---- ext/standard/tests/strings/bug37262.phpt | 8 +- tests/lang/bug17115.phpt | 17 ---- tests/lang/bug22690.phpt | 13 --- tests/lang/bug24926.phpt | 29 ------- 18 files changed, 6 insertions(+), 413 deletions(-) delete mode 100644 Zend/tests/anonymous_func_001.phpt delete mode 100644 Zend/tests/anonymous_func_002.phpt delete mode 100644 Zend/tests/anonymous_func_003.phpt delete mode 100644 Zend/tests/bug48693.phpt delete mode 100644 Zend/tests/closure_025.phpt delete mode 100644 Zend/tests/exception_012.phpt delete mode 100644 ext/opcache/tests/bug68252.phpt delete mode 100644 tests/lang/bug17115.phpt delete mode 100644 tests/lang/bug22690.phpt delete mode 100644 tests/lang/bug24926.phpt diff --git a/Zend/tests/anonymous_func_001.phpt b/Zend/tests/anonymous_func_001.phpt deleted file mode 100644 index 97b91b6544..0000000000 --- a/Zend/tests/anonymous_func_001.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Testing calls to anonymous function ---FILE-- - ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -int(0) -int(0) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(1) -int(1) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(2) -int(2) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(3) -int(3) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(4) -int(4) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(5) -int(5) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(6) -int(6) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(7) -int(7) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(8) -int(8) - -Deprecated: Function create_function() is deprecated in %s on line %d -int(9) -int(9) diff --git a/Zend/tests/anonymous_func_002.phpt b/Zend/tests/anonymous_func_002.phpt deleted file mode 100644 index 28adc357da..0000000000 --- a/Zend/tests/anonymous_func_002.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Testing anonymous function return as array key and accessing $GLOBALS ---FILE-- - ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d - -Deprecated: Function create_function() is deprecated in %s on line %d -int(2) -bool(true) diff --git a/Zend/tests/anonymous_func_003.phpt b/Zend/tests/anonymous_func_003.phpt deleted file mode 100644 index d2610310f7..0000000000 --- a/Zend/tests/anonymous_func_003.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Using throw $var with anonymous function return ---FILE-- -getMessage() == 'test'); -} - -?> ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -bool(true) diff --git a/Zend/tests/bug48693.phpt b/Zend/tests/bug48693.phpt deleted file mode 100644 index f916b6407b..0000000000 --- a/Zend/tests/bug48693.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -Bug #48693 (Double declaration of __lambda_func when lambda wrongly formatted) ---FILE-- - ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -ParseError: syntax error, unexpected '}', expecting end of file in %sbug48693.php(4) : runtime-created function:1 -Stack trace: -#0 %sbug48693.php(4): create_function('', 'return 1; }') -#1 {main} - - -Deprecated: Function create_function() is deprecated in %s on line %d - -Deprecated: Function create_function() is deprecated in %s on line %d -ParseError: syntax error, unexpected end of file in %sbug48693.php(14) : runtime-created function:1 -Stack trace: -#0 %sbug48693.php(14): create_function('', '{') -#1 {main} - - -Deprecated: Function create_function() is deprecated in %s on line %d -int(2) -int(3) diff --git a/Zend/tests/closure_025.phpt b/Zend/tests/closure_025.phpt deleted file mode 100644 index b3d03a7ad9..0000000000 --- a/Zend/tests/closure_025.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Closure 025: Using closure in create_function() ---FILE-- -__invoke(4)); - -?> ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -int(8) diff --git a/Zend/tests/exception_012.phpt b/Zend/tests/exception_012.phpt deleted file mode 100644 index 4a1070330a..0000000000 --- a/Zend/tests/exception_012.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Test exception doesn't cause RSHUTDOWN bypass, variation 1 ---INI-- -assert.bail=1 -assert.exception=1 ---FILE-- - ---EXPECTHEADERS-- -Content-type: text/html; charset=UTF-8 ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d - -Fatal error: Uncaught AssertionError: assert(false) in %sexception_012.php(%d) : runtime-created function:%d -Stack trace: -#0 %sexception_012.php(%d) : runtime-created function(%d): assert(false, 'assert(false)') -#1 %sexception_012.php(%d): __lambda_func() -#2 {main} - thrown in %sexception_012.php(%d) : runtime-created function on line %d diff --git a/Zend/tests/instanceof_001.phpt b/Zend/tests/instanceof_001.phpt index 8c13a0478c..ae33dab4a5 100644 --- a/Zend/tests/instanceof_001.phpt +++ b/Zend/tests/instanceof_001.phpt @@ -8,7 +8,7 @@ var_dump($a instanceof stdClass); var_dump(new stdCLass instanceof stdClass); -$b = create_function('', 'return new stdClass;'); +$b = function() { return new stdClass; }; var_dump($b() instanceof stdClass); $c = array(new stdClass); @@ -22,8 +22,6 @@ var_dump("$a" instanceof stdClass); --EXPECTF-- bool(true) bool(true) - -Deprecated: Function create_function() is deprecated in %s on line %d bool(true) bool(true) bool(false) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 3fce84d6a4..e8bcc1c980 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -67,7 +67,6 @@ static ZEND_FUNCTION(get_declared_traits); static ZEND_FUNCTION(get_declared_interfaces); static ZEND_FUNCTION(get_defined_functions); static ZEND_FUNCTION(get_defined_vars); -static ZEND_FUNCTION(create_function); static ZEND_FUNCTION(get_resource_type); static ZEND_FUNCTION(get_resources); static ZEND_FUNCTION(get_loaded_extensions); @@ -197,11 +196,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_get_defined_functions, 0, 0, 0) ZEND_ARG_INFO(0, exclude_disabled) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_create_function, 0, 0, 2) - ZEND_ARG_INFO(0, args) - ZEND_ARG_INFO(0, code) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_get_resource_type, 0, 0, 1) ZEND_ARG_INFO(0, res) ZEND_END_ARG_INFO() @@ -276,7 +270,6 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */ ZEND_FE(get_declared_interfaces, arginfo_zend__void) ZEND_FE(get_defined_functions, arginfo_get_defined_functions) ZEND_FE(get_defined_vars, arginfo_zend__void) - ZEND_DEP_FE(create_function, arginfo_create_function) ZEND_FE(get_resource_type, arginfo_get_resource_type) ZEND_FE(get_resources, arginfo_get_resources) ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions) @@ -1895,78 +1888,6 @@ ZEND_FUNCTION(get_defined_vars) } /* }}} */ -#define LAMBDA_TEMP_FUNCNAME "__lambda_func" -/* {{{ proto string create_function(string args, string code) - Creates an anonymous function, and returns its name (funny, eh?) */ -ZEND_FUNCTION(create_function) -{ - zend_string *function_name; - char *eval_code, *function_args, *function_code; - size_t eval_code_length, function_args_len, function_code_len; - int retval; - char *eval_name; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &function_args, &function_args_len, &function_code, &function_code_len) == FAILURE) { - return; - } - - eval_code = (char *) emalloc(sizeof("function " LAMBDA_TEMP_FUNCNAME) - +function_args_len - +2 /* for the args parentheses */ - +2 /* for the curly braces */ - +function_code_len); - - eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME "(") - 1; - memcpy(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(", eval_code_length); - - memcpy(eval_code + eval_code_length, function_args, function_args_len); - eval_code_length += function_args_len; - - eval_code[eval_code_length++] = ')'; - eval_code[eval_code_length++] = '{'; - - memcpy(eval_code + eval_code_length, function_code, function_code_len); - eval_code_length += function_code_len; - - eval_code[eval_code_length++] = '}'; - eval_code[eval_code_length] = '\0'; - - eval_name = zend_make_compiled_string_description("runtime-created function"); - retval = zend_eval_stringl(eval_code, eval_code_length, NULL, eval_name); - efree(eval_code); - efree(eval_name); - - if (retval==SUCCESS) { - zend_op_array *func; - HashTable *static_variables; - - func = zend_hash_str_find_ptr(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); - if (!func) { - zend_error_noreturn(E_CORE_ERROR, "Unexpected inconsistency in create_function()"); - RETURN_FALSE; - } - if (func->refcount) { - (*func->refcount)++; - } - static_variables = func->static_variables; - func->static_variables = NULL; - zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); - func->static_variables = static_variables; - - function_name = zend_string_alloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG, 0); - ZSTR_VAL(function_name)[0] = '\0'; - - do { - ZSTR_LEN(function_name) = snprintf(ZSTR_VAL(function_name) + 1, sizeof("lambda_")+MAX_LENGTH_OF_LONG, "lambda_%d", ++EG(lambda_count)) + 1; - } while (zend_hash_add_ptr(EG(function_table), function_name, func) == NULL); - RETURN_NEW_STR(function_name); - } else { - zend_hash_str_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME)-1); - RETURN_FALSE; - } -} -/* }}} */ - #if ZEND_DEBUG && defined(ZTS) ZEND_FUNCTION(zend_thread_id) { diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index fb21634885..6aea0f6007 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -258,7 +258,6 @@ static const func_info_t func_infos[] = { I1("get_declared_interfaces", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), F1("get_defined_functions", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY), I1("get_defined_vars", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF), - FN("create_function", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING), F1("get_resource_type", MAY_BE_NULL | MAY_BE_STRING), 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), F0("debug_print_backtrace", MAY_BE_NULL), diff --git a/ext/opcache/tests/bug68252.phpt b/ext/opcache/tests/bug68252.phpt deleted file mode 100644 index bc2e5a0fb6..0000000000 --- a/ext/opcache/tests/bug68252.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug #68252 (segfault in Zend/zend_hash.c in function _zend_hash_del_el) ---INI-- -opcache.enable=1 -opcache.enable_cli=1 -opcache.fast_shutdown=1 ---SKIPIF-- - ---FILE-- - ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -'' . "\0" . 'lambda_%d' +--EXPECT-- +'foo' . "\0" . 'bar' diff --git a/tests/lang/bug17115.phpt b/tests/lang/bug17115.phpt deleted file mode 100644 index 9500352799..0000000000 --- a/tests/lang/bug17115.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Bug #17115 (lambda functions produce segfault with static vars) ---FILE-- - ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -int(0) -int(1) -int(2) diff --git a/tests/lang/bug22690.phpt b/tests/lang/bug22690.phpt deleted file mode 100644 index 85ddcd3487..0000000000 --- a/tests/lang/bug22690.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Bug #22690 (ob_start() is broken with create_function() callbacks) ---FILE-- - -bar ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -BAR -BAR diff --git a/tests/lang/bug24926.phpt b/tests/lang/bug24926.phpt deleted file mode 100644 index f73d265f38..0000000000 --- a/tests/lang/bug24926.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Bug #24926 (lambda function (create_function()) cannot be stored in a class property) ---FILE-- -functions['test'] = $function; - print($this->functions['test']()); // werkt al niet meer - - } -} - -$a = new foo (); - -?> ---EXPECTF-- -Deprecated: Function create_function() is deprecated in %s on line %d -FOO -FOO -- 2.50.1