php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17781 Array assignment through method
Submitted: 2002-06-16 08:59 UTC Modified: 2002-06-16 11:08 UTC
From: Oliver dot Siegmar at xams dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.1.2 OS: Linux
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: Oliver dot Siegmar at xams dot org
New email:
PHP Version: OS:

 

 [2002-06-16 08:59 UTC] Oliver dot Siegmar at xams dot org
<?php
class testclass {
    function assign($var, $value) {
        $this->$var = $value;
    }
}

$testobj = new testclass();

$testobj->testvar = 20;
$testobj->assign("testvar", 30);
echo $testobj->testvar; // Result = 30 - very good!

$testobj->testarray["dim1"]["dim2"] = 20;
$testobj->assign("testarray[dim1][dim2]", 30);
echo $testobj->testarray["dim1"]["dim2"]; // Result = 20 - bad (should be 30)!
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-16 09:07 UTC] sander@php.net
This is just not possible. You can't specify a value of an array using variable variables.
 [2002-06-16 11:08 UTC] hholzgra@php.net
... but you could use eval() ...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC