php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26980 Array creation with '{}' instead of '[]'
Submitted: 2004-01-20 12:43 UTC Modified: 2004-01-20 14:26 UTC
From: reklov at unitedklasens dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.4 OS: Win98SE
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: reklov at unitedklasens dot de
New email:
PHP Version: OS:

 

 [2004-01-20 12:43 UTC] reklov at unitedklasens dot de
Description:
------------
With $var{$i} = 'Test' I wanted to create a variable with the name 'var1', using the '{}' and $i == 1, like ${$a} (http://www.php.net/manual/en/language.variables.variable.php)
Insted of this, it will create an array, as if I had used '[]' instead of '{}'.

Reproduce code:
---------------
<?php
$i = 1;
$var{$i} = 'Test';
echo $var{$i};
echo '<br>';
echo $var{1};
echo '<br>';
echo $var1;
?>

Expected result:
----------------
Test<br>
Test<br>  //not sure, what would happen...
Test

Actual result:
--------------
Test<br>
Test<br>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-20 14:26 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

{} can be used to denoted array or string indices.

You would need this: ${var${i}}

Nothe that the second \'{\' here is after the second \'$\' not before as in your code. The notation should force the compiler to generate code that concatenates the string var with the result of variable $i and use that as a variable name.

This is neither possible nor planned. You need to evaluate the value of the mentioned concatentaion yourself.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 05:01:42 2025 UTC