简体   繁体   中英

Is it standard to use “Defined Constant as a prefix for a function name” or a “Variable Function” in PHP?

This is the PHP Code:

define( 'FN_PREFIX', 'prefix_' );

${ FN_PREFIX . 'function_name' } = function( $string ) {
    echo $string;
};

$prefix_function_name( 'This is Working!!!' );

The Result:

This is Working!!!

No...! This is not at all standard .You have classes and methods with access specifiers and return types (PHP 7) to serve the purpose. Closure has different purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM