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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Thu Mar 28 08:01:28 2024 UTC