#33038 [Opn->Csd]: Name Variable After Variables

From: Date: Mon, 16 May 2005 04:40:23 +0000
Subject: #33038 [Opn->Csd]: Name Variable After Variables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-79029@lists.php.net to get a copy of this message
ID: 33038 Updated by: fmk@php.net Reported By: illicitcriminal at gmail dot com -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: Windows PHP Version: 4.3.10 New Comment: Already possible: <?php $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $length = strlen($alphabet); for ($i = 0; $i<$length; $i++) { $$alphabet{$i} = $i; } echo $a.'-'.$b.'-'.$c.'-'.$A.'-'.$B.'-'.$C; ?> result = 0-1-2-26-27-28 Previous Comments: ------------------------------------------------------------------------ [2005-05-16 04:18:54] illicitcriminal at gmail dot com Description: ------------ I think it'd be VERY useful to be able to declare/state variables based on the value of another variable. I've run into situations where it would save me a bit of time if this were possible. In "Reproduce Code", I'll show you a piece that would be useful for an encryption function that I wrote. Reproduce code: --------------- /* Giving Letters Numerical Values */ $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $length = strlen($alphabet); for ($cur=0;$cur<$length;$cur++){ $letter = substr($alphabet, $current, $current+1); $numberVal = $current+1; /* This is where my idea comes in to play. To be able to name the variable "a", referred to as $a (and b,c,d so on...). I've used the syntax ^$var to define the naming of the variable dependant on the value of $var (another variable)... */ ^$letter = $numberVal; } echo $a.'-'.$b.'-'.$c.'-'.$A.'-'.$B.'-'.$C; Expected result: ---------------- 1-2-3-26-27-28 Actual result: -------------- Probably an "unexpexted '^'" parse error. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33038&edit=1

« previous php.bugs (#79029) next »