Vorinitialisierte Funktionen in PHP

Mittels der interne PHP-Funktion create_function kann man durch einen Trick vorinitialisierte Funktionen definieren. So geht das.


function create_custom_function( $init ){
return create_function('$a','return $a + '.$init.';');
}

$func = create_custom_function( 5 );
echo $func(4); // prints 9
echo $func(6); // prints 6

Das kann in machen Fällen nützlich sein.

PHP

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments are closed.