【发布时间】:2017-07-16 23:18:12
【问题描述】:
是否可以动态设置 php 静态类变量?在下面的示例中,我想将要设置的变量的字符串表示形式传递给函数“databaseInit”,然后该函数设置变量...
class app {
static $database_smf;
static $database_phpbb;
/**
* Initialise the app
*/
static function init(){
// No initialise the db connection
self::databaseInit('database_phpbb');
self::databaseInit('database_smf');
}
static function databaseInit( $database ){
// is it possible to dynamically set the static var based on the param provided? eg:
self::[$database] = true;
}
}
【问题讨论】:
-
您链接的问题不是直截了当的,答案也不是。所以,从技术上讲是的,但我想说这个问题将帮助其他人更有效地解决问题:D
标签: php