php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30202 $array[xyz] = xyz; doesn't work inside a class
Submitted: 2004-09-22 23:41 UTC Modified: 2004-09-22 23:48 UTC
From: james at processit dot biz Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.0.0 OS: Windows Server 2003
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: james at processit dot biz
New email:
PHP Version: OS:

 

 [2004-09-22 23:41 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-22 23:48 UTC] derick@php.net
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.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 01:01:28 2024 UTC