create_function

PHP 4 >= 4.0.1, PHP 5, PHP 7 Deprecated: PHP 7.2.0
create_function - Create a function dynamically by evaluating a string of code
Manual
Code Examples

create_function( string$args, string$code ): string

Creates a function dynamically from the parameters passed, and returns a unique name for it.

Caution:

This function internally performs an eval and as such has the same security issues as eval. It also has bad performance and memory usage characteristics, because the created functions are global and can not be freed.

A native anonymous function should be used instead.

Parameters

It is normally advisable to pass these parameters as single quoted strings. If using double quoted strings, variable names in the code need to be escaped carefully, e.g. \$somevar.

args

The function arguments, as a single comma-separated string.

code

The function code.

Return Values

Returns a unique function name as a string, or false on failure. Note that the name contains a non-printable character ("\0"), so care should be taken when printing the name or incorporating it in any other string.

Example of create_function

Show all examples for create_function

PHP Version:


Function create_function:

Function Handling Functions

Most used PHP functions