Edit report at http://bugs.php.net/bug.php?id=53720&edit=1
ID: 53720 Comment by: kh dot wild at wicom dot li Reported by: kh dot wild at wicom dot li Summary: Access variable in class dynamicaly Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: freebsd, osx PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Thank you very much. I've got it. $this->{$x}[ 1 ] = 9999; is working. Previous Comments: ------------------------------------------------------------------------ [2011-01-12 21:25:29] fel...@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 This is expected, see: When you do: $x = 'cicoordinator'; $this->${x}[ 1 ] = 9999; You are doing '$this->i = 9999;', because ${x}[1] == 'i' (c[i]coordinator) ------------------------------------------------------------------------ [2011-01-12 13:14:57] kh dot wild at wicom dot li Description: ------------ It seems, that when I read a class variable with the varname in a string, it works, but writing in the same way doesn't Test script: --------------- <? class XXX { private $cisupport = Array( 1 ); private $cicoordinator = Array(); function support() { $x = 'cisupport'; print( "Request support static:\n"); print_r( $this->cisupport ); print( "Request support dynamic:\n"); print_r( $this->$x ); } function coordinator() { $x = 'cicoordinator'; print( "Set coordinator static:\n"); $this->cicoordinator[ 1 ] = 12; print_r( $this->cicoordinator ); print( "Set coordinator dynamic:\n"); $this->${x}[ 1 ] = 9999; print_r( $this->${x} ); } } $x = new XXX; $x->support(); $x->coordinator(); ?> Expected result: ---------------- Request support static: Array ( [0] => 1 ) Request support dynamic: Array ( [0] => 1 ) Set coordinator static: Array ( [1] => 12 ) Set coordinator dynamic: Array ( [1] => 9999 ) Actual result: -------------- Request support static: Array ( [0] => 1 ) Request support dynamic: Array ( [0] => 1 ) Set coordinator static: Array ( [1] => 12 ) Set coordinator dynamic: Array ( [1] => 12 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53720&edit=1