]> granicus.if.org Git - php/commitdiff
Remove create_function()
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 28 Jan 2019 11:41:36 +0000 (12:41 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 28 Jan 2019 14:58:23 +0000 (15:58 +0100)
Deprecated in PHP 7.2 as part of
https://wiki.php.net/rfc/deprecations_php_7_2.

18 files changed:
Zend/tests/anonymous_func_001.phpt [deleted file]
Zend/tests/anonymous_func_002.phpt [deleted file]
Zend/tests/anonymous_func_003.phpt [deleted file]
Zend/tests/bug48693.phpt [deleted file]
Zend/tests/closure_025.phpt [deleted file]
Zend/tests/exception_012.phpt [deleted file]
Zend/tests/instanceof_001.phpt
Zend/zend_builtin_functions.c
ext/opcache/Optimizer/zend_func_info.c
ext/opcache/tests/bug68252.phpt [deleted file]
ext/standard/tests/general_functions/print_r.phpt
ext/standard/tests/general_functions/print_r_64bit.phpt
ext/standard/tests/general_functions/var_dump.phpt
ext/standard/tests/general_functions/var_dump_64bit.phpt
ext/standard/tests/strings/bug37262.phpt
tests/lang/bug17115.phpt [deleted file]
tests/lang/bug22690.phpt [deleted file]
tests/lang/bug24926.phpt [deleted file]

diff --git a/Zend/tests/anonymous_func_001.phpt b/Zend/tests/anonymous_func_001.phpt
deleted file mode 100644 (file)
index 97b91b6..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
---TEST--
-Testing calls to anonymous function
---FILE--
-<?php
-
-for ($i = 0; $i < 10; $i++) {
-       $a = create_function('', 'return '. $i .';');
-       var_dump($a());
-
-       $b = "\0lambda_". ($i + 1);
-       var_dump($b());
-}
-
-?>
---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 (file)
index 28adc35..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
---TEST--
-Testing anonymous function return as array key and accessing $GLOBALS
---FILE--
-<?php
-
-$test = create_function('$v', 'return $v;');
-
-$arr = array(create_function('', 'return $GLOBALS["arr"];'), 2);
-
-var_dump($arr[$test(1)]);
-var_dump($arr[$test(0)]() == $arr);
-
-?>
---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 (file)
index d261031..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
---TEST--
-Using throw $var with anonymous function return
---FILE--
-<?php
-
-try {
-       $a = create_function('', 'return new Exception("test");');
-       throw $a();
-} catch (Exception $e) {
-       var_dump($e->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 (file)
index f916b64..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
---TEST--
-Bug #48693 (Double declaration of __lambda_func when lambda wrongly formatted)
---FILE--
-<?php
-
-try {
-       $x = create_function('', 'return 1; }');
-} catch (ParseError $e) {
-       echo "$e\n\n";
-}
-try {
-       $y = create_function('', 'function a() { }; return 2;');
-} catch (ParseError $e) {
-       echo "$e\n\n";
-}
-try {
-       $z = create_function('', '{');
-} catch (ParseError $e) {
-       echo "$e\n\n";
-}
-try {
-       $w = create_function('', 'return 3;');
-} catch (ParseError $e) {
-       echo "$e\n\n";
-}
-
-var_dump(
-       $y(),
-       $w()
-);
-
-?>
---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 (file)
index b3d03a7..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-Closure 025: Using closure in create_function()
---FILE--
-<?php
-
-$a = create_function('$x', 'return function($y) use ($x) { return $x * $y; };');
-
-var_dump($a(2)->__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 (file)
index 4a10703..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
---TEST--
-Test exception doesn't cause RSHUTDOWN bypass, variation 1
---INI--
-assert.bail=1
-assert.exception=1
---FILE--
-<?php
-
-$func = create_function('', 'define("Mommy", 1); assert(false);');
-$func();
-
-?>
---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
index 8c13a0478c1dc3c8fe77acb56189dcc9a993855c..ae33dab4a5bb2c595276ce33394474c85fe95754 100644 (file)
@@ -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)
index 3fce84d6a47d21e73ecd6e2a6b686ad5e76d1b82..e8bcc1c980e25392b2dd9a1f19f49af362dfab33 100644 (file)
@@ -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)
 {
index fb216348858eec2863b8da66dd2900536857a575..6aea0f600710989cde95ab9b56ec36a544013612 100644 (file)
@@ -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 (file)
index bc2e5a0..0000000
+++ /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--
-<?php require_once('skipif.inc'); ?>
---FILE--
-<?php
-/* run this test script with valgrind */
-function a() {
-       echo "okey";
-}
-
-create_function('', 'var_dump("22");');
-
-a();
---EXPECTF--
-Deprecated: Function create_function() is deprecated in %s on line %d
-okey
index fe02a97c181820e80450b9c9a2627f2c24006373..de58dd1e1e9e17db1b8262f7a10c1c1183ee158b 100644 (file)
@@ -271,15 +271,7 @@ $misc_values = array (
 /* calling check_printr() to display miscelleneous data using print_r() */
 check_printr($misc_values);
 
-/* checking print_r() on functions */
-echo "\n*** Testing print_r() on anonymous functions ***\n";
-$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
-echo "New anonymous function: $newfunc\n";
-print_r( $newfunc(2, 3) );
-/* creating anonymous function dynamically */
-print_r( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
-
-echo "\n\n*** Testing error conditions ***\n";
+echo "\n*** Testing error conditions ***\n";
 //passing zero argument
 var_dump( print_r() );
 
@@ -1715,14 +1707,6 @@ Array
 
 
 
-*** Testing print_r() on anonymous functions ***
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-New anonymous function: \0lambda_1
-2 * 3 = 6
-Deprecated: Function create_function() is deprecated in %s on line %d
-\0lambda_2
-
 *** Testing error conditions ***
 
 Warning: print_r() expects at least 1 parameter, 0 given in %s on line %d
index 5447a94db8cd6e569b3b36509cfd1d137369f36d..ff9c3c0b9c54e180abe7e1db1cc93cb3b742d8ec 100644 (file)
@@ -275,15 +275,7 @@ $misc_values = array (
 /* calling check_printr() to display miscelleneous data using print_r() */
 check_printr($misc_values);
 
-/* checking print_r() on functions */
-echo "\n*** Testing print_r() on anonymous functions ***\n";
-$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
-echo "New anonymous function: $newfunc\n";
-print_r( $newfunc(2, 3) );
-/* creating anonymous function dynamically */
-print_r( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
-
-echo "\n\n*** Testing error conditions ***\n";
+echo "\n*** Testing error conditions ***\n";
 //passing zero argument
 var_dump( print_r() );
 
@@ -1719,14 +1711,6 @@ Array
 
 
 
-*** Testing print_r() on anonymous functions ***
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-New anonymous function: \0lambda_1
-2 * 3 = 6
-Deprecated: Function create_function() is deprecated in %s on line %d
-\0lambda_2
-
 *** Testing error conditions ***
 
 Warning: print_r() expects at least 1 parameter, 0 given in %s on line %d
index f0da840c3b71b4f8203ed1b31d81e53d25245a91..74f497da6527fab16328ce2abd73822e29723b52 100644 (file)
@@ -274,14 +274,6 @@ echo "\n*** Testing var_dump() on multiple arguments ***\n";
 var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
           $objects, $misc_values, $variations );
 
-/* checking var_dump() on functions */
-echo "\n*** Testing var_dump() on anonymous functions ***\n";
-$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
-echo "New anonymous function: $newfunc\n";
-var_dump( $newfunc(2, 3) );
-/* creating anonymous function dynamically */
-var_dump( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
-
 echo "\n*** Testing error conditions ***\n";
 //passing zero argument
 var_dump();
@@ -1562,15 +1554,6 @@ array(6) {
   }
 }
 
-*** Testing var_dump() on anonymous functions ***
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-New anonymous function: \0lambda_1
-string(9) "2 * 3 = 6"
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-string(9) "\0lambda_2"
-
 *** Testing error conditions ***
 
 Warning: var_dump() expects at least 1 parameter, 0 given in %s on line %d
index a2476ef3f628a623aaeb7bf0180931a19501268a..8440ffaf6e508a0f5280893919997775d9fba6fa 100644 (file)
@@ -274,14 +274,6 @@ echo "\n*** Testing var_dump() on multiple arguments ***\n";
 var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
           $objects, $misc_values, $variations );
 
-/* checking var_dump() on functions */
-echo "\n*** Testing var_dump() on anonymous functions ***\n";
-$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
-echo "New anonymous function: $newfunc\n";
-var_dump( $newfunc(2, 3) );
-/* creating anonymous function dynamically */
-var_dump( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
-
 echo "\n*** Testing error conditions ***\n";
 //passing zero argument
 var_dump();
@@ -1562,15 +1554,6 @@ array(6) {
   }
 }
 
-*** Testing var_dump() on anonymous functions ***
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-New anonymous function: \0lambda_1
-string(9) "2 * 3 = 6"
-
-Deprecated: Function create_function() is deprecated in %s on line %d
-string(9) "\0lambda_2"
-
 *** Testing error conditions ***
 
 Warning: var_dump() expects at least 1 parameter, 0 given in %s on line %d
index b964c4a6592f0c52184a92176233d491c8c7690f..92abb29206c9c06b00be73233acd314c7510c445 100644 (file)
@@ -2,9 +2,7 @@
 Bug #37262 (var_export() does not escape \0 character)
 --FILE--
 <?php
-$func = create_function('$a', 'return $a;');
-var_export($func);
+var_export("foo\0bar");
 ?>
---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 (file)
index 9500352..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-Bug #17115 (lambda functions produce segfault with static vars)
---FILE--
-<?php
-$func = create_function('','
-       static $foo = 0;
-       return $foo++;
-');
-var_dump($func());
-var_dump($func());
-var_dump($func());
-?>
---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 (file)
index 85ddcd3..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-Bug #22690 (ob_start() is broken with create_function() callbacks)
---FILE--
-<?php
-       $foo = create_function('$s', 'return strtoupper($s);');
-       ob_start($foo);
-       echo $foo("bar\n");
-?>
-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 (file)
index f73d265..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-Bug #24926 (lambda function (create_function()) cannot be stored in a class property)
---FILE--
-<?php
-
-error_reporting (E_ALL);
-
-class foo {
-
-    public $functions = array();
-
-    function __construct()
-    {
-        $function = create_function('', 'return "FOO\n";');
-        print($function());
-
-        $this->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