note 38171 added to language.variables.variable

From: Date: Wed, 10 Dec 2003 17:37:42 +0000
Subject: note 38171 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-61762@lists.php.net to get a copy of this message
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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38171 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38171&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38171&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61762) next »