我有一個這樣的靜態類。擁有一組參數,將它們替換爲%s的順序
<?php
class Language
{
public static $language = array();
var $config;
function __construct($config)
{
switch(strtoupper($config['LANGUAGE']))
{
case 'ENGLISH':
self::setEnglish();
break;
case 'TURKISH':
self::setTurkish();
break;
default:
self::setEnglish();
}
}
public static function setEnglish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator initialized!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'A function returned false.',
);
}
public static function setTurkish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator çalışıyor!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'Bir fonksiyon false döndürdü.',
);
}
public static function getLanguage($key)
{
return isset(self::$language[$key]) ? self::$language[$key] : $key;
}
}
?>
它被這樣使用,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED')
,但我要通過更多的參數。與此類似,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED', array(__FUNCTION__))
這些參數應按順序傳遞,如%s。最後看起來應該是這樣的:
"A function returned false" to;
"%s function returned false"
And output would be;
"myLovelyFunction() returned false" (the first array parameter, which is __FUNCTION__)
聽起來像小菜一碟我的大腦停止atm。
我該怎麼做?
只需使用sprintf? – Philipp