php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33038 Name Variable After Variables
Submitted: 2005-05-16 04:18 UTC Modified: 2005-05-16 21:29 UTC
From: illicitcriminal at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.10 OS: Windows
Private report: No CVE-ID: None
 [2005-05-16 04:18 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-16 06:40 UTC] fmk@php.net
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
 [2005-05-16 21:29 UTC] derick@php.net
No bug or new feature -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 06:01:32 2024 UTC