Date: 12/06/00
- Next message: anonymous <email protected>: "[PHP-DEV] CVS Account Request"
- Previous message: Hartmut Holzgraefe: "Re: [PHP-DEV] /tests -> run-tests.php"
- Next in thread: wstockal <email protected>: "[PHP-DEV] PHP 4.0 Bug #8130 Updated: Changing a copy of an array affects the original"
- Maybe reply: wstockal <email protected>: "[PHP-DEV] PHP 4.0 Bug #8130 Updated: Changing a copy of an array affects the original"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 8130
User Update by: wstockal <email protected>
Status: Open
Bug Type: Arrays related
Description: Changing a copy of an array affects the original
OK, this only affects objects in the array whose methods
have been accessed. Other objects are still copies. It
also works on php-4.0.3pl1 on the Win32 platform.
Previous Comments:
---------------------------------------------------------------------------
[2000-12-05 20:28:28] wstockal <email protected>
A short script:
<?php
class test_class_2{
var $name;
function distort_reality(){
echo("Method Called.<br>n");
return;
}
}
$a[] = new test_class_2;
$a[0]->name = 'Original';
echo('$b = $a<br>'."n");
$b = $a;
echo("Original contains: {$a[0]->name}<br>n");
echo("Copy contains: {$b[0]->name}<br><p>n");
echo("Change contents for $b<br>n");
$b[0]->name = 'Copy';
echo("Original contains: {$a[0]->name}<br>n");
echo("Copy contains: {$b[0]->name}<br><p>n");
$a[0]->distort_reality();
echo('Once again, $b = $a<br>'."n");
$b = $a;
echo("Original contains: {$a[0]->name}<br>n");
echo("Copy contains: {$b[0]->name}<br><p>n");
echo("Change contents for $b<br>n");
$b[0]->name = 'Copy';
echo("Original contains: {$a[0]->name}<br>n");
echo("Copy contains: {$b[0]->name}<br>n");
?>
The output from the script:
$b = $a
Original contains: Original
Copy contains: Original
Change contents for $b
Original contains: Original
Copy contains: Copy
Method Called.
Once again, $b = $a
Original contains: Original
Copy contains: Original
Change contents for $b
Original contains: Copy
Copy contains: Copy
Basically, if $a is an array of objects and any method of an object is called any subsequent copy of $a becomes linked to the original. Any change to the copy propagates through to the original.
Configure line:
'./configure' '--with-config-file-path=/usr/local/stronghold/conf' '--with-apxs=/usr/local/stronghold/bin/apxs' '--enable-versioning' '--disable-debug' '--with-zlib' '--with-gd=/usr/local' '--with-gdbm' '--with-db2' '--with-mysql' '--with-xml' '--with-ldap' '--with-cpdflib=/usr/local' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-tiff-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--enable-sysvshm=yes' '--enable-sysvsem=yes' '--enable-track-vars=yes' '--enable-bcmath=yes' '--enable-memory-limit=yes'
Running as a module under apache 1.3.14
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8130
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: anonymous <email protected>: "[PHP-DEV] CVS Account Request"
- Previous message: Hartmut Holzgraefe: "Re: [PHP-DEV] /tests -> run-tests.php"
- Next in thread: wstockal <email protected>: "[PHP-DEV] PHP 4.0 Bug #8130 Updated: Changing a copy of an array affects the original"
- Maybe reply: wstockal <email protected>: "[PHP-DEV] PHP 4.0 Bug #8130 Updated: Changing a copy of an array affects the original"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

