php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67987 Pushing a new array element, changes existing array elements to its valu
Submitted: 2014-09-09 08:58 UTC Modified: 2014-09-09 10:22 UTC
From: main32 at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.5.16 OS: Windows 8.1 64Bit
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: main32 at gmail dot com
New email:
PHP Version: OS:

 

 [2014-09-09 08:58 UTC] main32 at gmail dot com
Description:
------------
Pushing a new array element(class), changes existing array elements to its value.



Test script:
---------------
<?php

	class PC
	{
		
	}
	
	class Part
	{
		
	}
	
	$part = new Part();
	
	$pc = new PC();
	
	$part->name = 'CPU';
	$pc->arr[] = $part;
	$part->name = 'GPU';
	$pc->arr[] = $part;
	
	print_r($pc);

?>

Expected result:
----------------
PC Object ( [arr] => Array ( [0] => Part Object ( [name] => CPU ) [1] => Part Object ( [name] => GPU ) ) )

Actual result:
--------------
PC Object ( [arr] => Array ( [0] => Part Object ( [name] => GPU ) [1] => Part Object ( [name] => GPU ) ) )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-09 10:22 UTC] datibbaw@php.net
-Status: Open +Status: Not a bug
 [2014-09-09 10:22 UTC] datibbaw@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 basically how objects works. See also:

http://php.net/manual/en/language.oop5.references.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 11:01:34 2024 UTC