Bug #16954 Updated: Scope loss when using layered/arrayed objects.

From: Date: Sat, 01 Jun 2002 14:11:01 +0000
Subject: Bug #16954 Updated: Scope loss when using layered/arrayed objects.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-9065@lists.php.net to get a copy of this message
ID: 16954 Updated by: mfischer@php.net Reported By: fhirsch@tse.com -Status: Open +Status: Closed Bug Type: Class/Object related Operating System: Linux 2.4 PHP Version: 4.2.0 New Comment: This happens due to automatic object copying in ZE1. You can try to work this around by using only references but I already can foresee that it won't work in all cases. This is changed in ZE2 which does not automatically copy objects anymore. Previous Comments: ------------------------------------------------------------------------ [2002-05-01 17:15:16] fhirsch@tse.com I am having difficulty writing a test case for this problem, as it is somewhat complex. Here is the scenario: I have an object that contains an array of data. Some array elements may be scalar, some arrays and some objects. The object of the array contains in itself another array of objects (containing core data) and accessor methods to act on the data objects. My script uses the following methodology on this object: $var = "PHP Rules"; $test = ""; while ($mydata = $obj->arrayname[object_key]->fields) { // Do some work $test = "HERE I AM!"; $var .= $mydata[xyz] . "MODIFIED"; $obj->arrayname[object_key]->MoveNext(); } print "$var$test"; I might get concerned here that my object layering is too deep. However, the key issue here is that $var and for that matter ANY variable used or modified inside the while loop does not carry its changes outside. This means the print statement outputs "PHP Rules" only. Adding prints inside the while loop outputs fine. I will try to find a workaround for now. Thanks for your help, Fred ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16954&edit=1

« previous php.bugs (#9065) next »