From:             [EMAIL PROTECTED]
Operating system: Linux 2.2
PHP version:      4.0.4
PHP Bug Type:     Variables related
Bug description:  Variable Variables and Constants

Variable variables techniques do not work when one of the
"variables" is a constant. The example below illustrates
this. This is probably the desired behavior for constants,
but was confusing for me when I was trying to figure it out.
The alternative I used was to add the variables I needed to
the $GLOBALS array instead of defining them as constants.

<?php

define("DB_X_NAME","database1");
define("DB_Y_NAME","database2");
$DB_Z_NAME="database3";


function connectTo($databaseName){
global $DB_Z_NAME;

$fullDatabaseName="DB_".$databaseName."_NAME";
return "\"".${$fullDatabaseName}."\"";

}

print "DB_X_NAME is ".connectTo("X")."
";
print "DB_Y_NAME is ".connectTo("Y")."
";
print "DB_Z_NAME is ".connectTo("Z")."
";

?>


-- 
Edit Bug report at: http://bugs.php.net/?id=10801&edit=1



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to