#30202 [Opn->Bgs]: $array[xyz] = xyz; doesn't work inside a class

From: Date: Wed, 22 Sep 2004 21:48:35 +0000
Subject: #30202 [Opn->Bgs]: $array[xyz] = xyz; doesn't work inside a class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-66575@lists.php.net to get a copy of this message
 ID:               30202
 Updated by:       derick@php.net
 Reported By:      james at processit dot biz
-Status:           Open
+Status:           Bogus
 Bug Type:         *General Issues
 Operating System: Windows Server 2003
 PHP Version:      5.0.0
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

.


Previous Comments:
------------------------------------------------------------------------

[2004-09-22 23:41:50] james at processit dot biz

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30202&edit=1


Thread (2 messages)

« previous php.bugs (#66575) next »