简体   繁体   English

在 PHP 中使用“定义的常量作为 function 名称的前缀”或“变量函数”是否标准?

[英]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:这是 PHP 代码:

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.这根本不是标准的。您可以使用带有访问说明符和返回类型(PHP 7)的类和方法来达到此目的。 Closure has different purpose.闭包有不同的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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