[PHP-DEV] Bug #8130 Updated: Changing a copy of an array affects the original

2001-08-28 Thread wstockal

ID: 8130
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Status: Closed
Bug Type: Scripting Engine problem
Operating System: Redhat Linux 6.2
PHP Version: 4.0.6-dev
New Comment:

This problem can also affect the private copies of variables
used inside of functions.

Script:

  class test {
var $property;
function do_something(){
 return;
}
  }
  function mangle($array_in) {
   $array_in[0]-property = 'trashed';
  }
  $array[0] = new test;
  $array[0]-property = 'ok';
  mangle($array);
  echo(h2Before:/h2\n);
  echo(\$array[0]-property is {$array[0]-property}br\n);
  $array[0]-do_something();
  mangle($array);
  echo(h2After:/h2\n);
  echo(\$array[0]-property is {$array[0]-property}br\n);


Output:

h2Before:/h2
$array[0]-property is okbr
h2After:/h2
$array[0]-property is trashedbr


Previous Comments:


[2001-06-17 04:54:11] [EMAIL PROTECTED]

This will not be fixed anytime soon. It is a deep seated problem in the implementation 
and fixing it would cause speed problems and numerous other problems, This is somthing 
that can be coded around too so should not cause massive problems.

- James



[2001-04-28 15:27:42] [EMAIL PROTECTED]

Reproduced in 4.0.6-dev one for the bug squash



[2001-01-06 02:38:08] [EMAIL PROTECTED]

Confirmed in 4.0.4pl1 RC1



[2000-12-07 02:28:51] [EMAIL PROTECTED]

Is this the same as bug 6417?



[2000-12-06 11:23:23] [EMAIL PROTECTED]

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.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/?id=8130


Edit this bug report at http://bugs.php.net/?id=8130edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #8130 Updated: Changing a copy of an array affects the original

2001-06-18 Thread jmoore

ID: 8130
Updated by: jmoore
Reported By: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: Scripting Engine problem
Operating system: 
PHP Version: 4.0.6-dev
Assigned To: 
Comments:

This will not be fixed anytime soon. It is a deep seated problem in the implementation 
and fixing it would cause speed problems and numerous other problems, This is somthing 
that can be coded around too so should not cause massive problems.

- James

Previous Comments:
---

[2001-04-28 15:27:42] [EMAIL PROTECTED]
Reproduced in 4.0.6-dev one for the bug squash

---

[2001-01-06 02:38:08] [EMAIL PROTECTED]
Confirmed in 4.0.4pl1 RC1

---

[2000-12-07 02:28:51] [EMAIL PROTECTED]
Is this the same as bug 6417?

---

[2000-12-06 11:23:23] [EMAIL PROTECTED]
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.

---

[2000-12-05 20:28:28] [EMAIL PROTECTED]
A short script:
?php
  class test_class_2{
var $name;
function distort_reality(){
 echo(Method Called.brn);
 return;
}
  }
  $a[] = new test_class_2;
  $a[0]-name = 'Original';
  echo('$b = $abr'.n);
  $b = $a;
  echo(Original contains: {$a[0]-name}brn);
  echo(Copy contains: {$b[0]-name}brpn);
  echo(Change contents for $bbrn);
  $b[0]-name = 'Copy';
  echo(Original contains: {$a[0]-name}brn);
  echo(Copy contains: {$b[0]-name}brpn);
  $a[0]-distort_reality();
  echo('Once again, $b = $abr'.n);
  $b = $a;
  echo(Original contains: {$a[0]-name}brn);
  echo(Copy contains: {$b[0]-name}brpn);
  echo(Change contents for $bbrn);
  $b[0]-name = 'Copy';
  echo(Original contains: {$a[0]-name}brn);
  echo(Copy contains: {$b[0]-name}brn);
?

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

---

The remainder of the comments for this report are too long.  To view the rest of the 
comments, please view the bug report online.


ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=8130edit=2


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]