php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16954 Scope loss when using layered/arrayed objects.
Submitted: 2002-05-01 17:15 UTC Modified: 2002-06-01 10:11 UTC
From: fhirsch at tse dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.2.0 OS: Linux 2.4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fhirsch at tse dot com
New email:
PHP Version: OS:

 

 [2002-05-01 17:15 UTC] fhirsch at tse dot 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-01 10:11 UTC] mfischer@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC