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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 11:01:34 2024 UTC