Unless you mess with reflection, the only way I can think of to have a static private/protected class property with a dynamically generated value is to calculate it outside the class:
class Foo {
protected static $dbname = DBNAME;
public static function debug() {
return Foo::$dbname;
}
}
$appdata = array(
'id' => 31416,
);
define('DBNAME', 'mydb_'.$appdata['id']);
var_dump(Foo::debug());
In your precise use case, however, it's possible that there's simply no good reason for the property to be static. In that case, it's as straightforward as using the constructor:
class Foo {
protected $dbname;
public function __construct($appdata){
$this->dbname = 'mydb_'.$appdata['id'];
}
public function debug() {
return $this->dbname;
}
}
$appdata = array(
'id' => 31416,
);
$foo = new Foo($appdata);
var_dump($foo->debug());