Bug #10801 Updated: Variable Variables and Constants

From: Date: Thu, 10 May 2001 22:56:56 +0000
Subject: Bug #10801 Updated: Variable Variables and Constants
Groups: php.dev 
Request: Send a blank email to php-dev+get-54803@lists.php.net to get a copy of this message
ID: 10801 Updated by: cynic Reported By: mstearne@entermix.com Old-Status: Open Status: Bogus Bug Type: Variables related Operating system: PHP Version: 4.0.4 Assigned To: Comments: it's variable variables, not variable constants. what bug are you reporting? I haven't noticed. Previous Comments: --------------------------------------------------------------------------- [2001-05-10 18:11:18] mstearne@entermix.com 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")." "; ?> --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=10801&edit=2

« previous php.dev (#54803) next »