Re: [PHP4BETA] Arrays inside classes (repost)

From: Date: Wed, 09 Feb 2000 22:47:11 +0000
Subject: Re: [PHP4BETA] Arrays inside classes (repost)
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-10000@lists.php.net to get a copy of this message
At 17:59 09/02/2000 , Faisal Nasim wrote:
Hello! Any info on this? Faisal. ----- Original Message ----- From: "Faisal Nasim" <faisal@nasim.org> To: <php4beta@lists.php.net> Sent: Wednesday, February 09, 2000 1:24 PM Subject: [PHP4BETA] Arrays inside classes : Hi, : : Can anybody tell me how to make the copy of array when accessing : through classes' functions? : : TEST CASE: : : <? : class myclass : {
:     var $MYARRAY;
:
:     function myclass ()
:     {
:       $this->MYARRAY[] = "faisal";
:       $this->MYARRAY[] = "nasim";
:     }
:
:     function test ()
:     {
:       $x = $this -> MYARRAY; # I want a copy!
:       unset ( $x[0] );
:     }
: } : : $test = new myclass; : : print count ( $test -> MYARRAY ) . "<BR>"; # 2 : $test -> test (); : print count ( $test -> MYARRAY ) . "<BR>"; # 1 !! : ?> : : : : I would like to make a copy of $MYARRAY in test().... I am not : using & to point to the same address, so by default it should : create a copy and not a reference! : : Any thoughts?
I acknowledge the problem, we'll try to address it tomorrow. The easiest way to reproduce it, by the way, doesn't involve classes at all: $foo[] = 1; $foo[] = 2; $bar = $foo; unset($foo[0]); print count($foo)."\n"; print count($bar)."\n"; Both count()'s will print 1, which is wrong. If you could submit a bug report (bugs.php.net/version4/) to ensure that this bug doesn't slip away, I'd be grateful. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.version4 (#10000) next »