|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10801 Variable Variables and Constants
Submitted: 2001-05-10 18:11 UTC Modified: 2001-05-10 19:26 UTC
From: mstearne at entermix dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0.4 OS: Linux 2.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mstearne at entermix dot com
New email:
PHP Version: OS:


 [2001-05-10 18:11 UTC] mstearne at entermix dot 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.



function connectTo($databaseName){
global $DB_Z_NAME;

return "\"".${$fullDatabaseName}."\"";


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



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-10 18:56 UTC]
it's variable variables, not variable constants.
what bug are you reporting? I haven't noticed.
 [2001-05-10 19:13 UTC] mstearne at entermix dot com
I'm not trying to change the constant value, but there
should be an interface for referencing constants similar to
how variables can be added.

If I have constants called:  MY_CONSTANT_1 and MY_CONSTANT_2

I should be about to form a variable that reference those
names like:



print $$thisConst;

print $$thisConst;

That would output:

 [2001-05-10 19:19 UTC]
there _is_ such an interface:
 [2001-05-10 19:26 UTC] mstearne at entermix dot com
Cool.  That's it.  Hmm, maybe you should classify this bug
as RTFM.  :-)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 10:01:31 2024 UTC