Bug #67987 [Opn->Nab]: Pushing a new array element, changes existing array elements to its valu

From: Date: Tue, 09 Sep 2014 10:22:56 +0000
Subject: Bug #67987 [Opn->Nab]: Pushing a new array element, changes existing array elements to its valu
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187474@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67987&edit=1 ID: 67987 Updated by: datibbaw@php.net Reported by: main32 at gmail dot com Summary: Pushing a new array element, changes existing array elements to its valu -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Windows 8.1 64Bit PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2014-09-09 08:58:19] 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 ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67987&edit=1

« previous php.bugs (#187474) next »