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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 02:01:35 2025 UTC