|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-12 13:14 UTC] 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
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Feb 11 17:00:01 2026 UTC |
Thank you very much. I've got it. $this->{$x}[ 1 ] = 9999; is working.