note 38171 deleted from language.variables.variable by nlopess
| From: | nlopess@php.net | Date: | Sat, 22 May 2004 08:17:48 +0000 |
| Subject: | note 38171 deleted from language.variables.variable by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69941@lists.php.net to get a copy of this message | ||
Note Submitter: zebedee
----
I needed to use variable constants, but as mstearne at entermix dot com correctly pointed out,
"Variable variables techniques do not work when one of the "variables" is a
constant."
Instead, you need to use the constant function. I have updated mstearne's code to show this.
<?php
define("DB_X_NAME","database1");
define("DB_Y_NAME","database2");
function connectTo($databaseName){
$fullDatabaseName="DB_".$databaseName."_NAME";
return "\"".constant($fullDatabaseName)."\"";
}
print "DB_X_NAME is ".connectTo("X")."<br>";
print "DB_Y_NAME is ".connectTo("Y")."<br>";
?>