|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2004-09-22 23:48 UTC] derick@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 04:00:01 2025 UTC | 
Description: ------------ In a function inside a class, I can only set array elements through the $xyz = array("key"=>"val") syntax. If I attempt to set with $xyz['key'] = 'val', the whole array is replaced with 'val' and it just becomes a normal variable, not an array. Reproduce code: --------------- <?php class Test { public $array; function arraytester() { $this->$array = array("key1"=>"val1", "key2"=>"val2"); print_r($this->$array); $this->$array['key1'] = 'val3'; print_r($this->$array); } } $class = new Test; $class->arraytester(); ?> Expected result: ---------------- Array ( [key1] => val1 [key2] => val2 ) Array ( [key1] => val3 [key2] => val2 ) Actual result: -------------- Array ( [key1] => val1 [key2] => val2 ) val3