php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9643 Variable member value gets lost from object during use
Submitted: 2001-03-08 20:07 UTC Modified: 2001-03-29 11:32 UTC
From: robsta at bigfoot dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.0.4pl1 OS: Debian 2.2 testing/unstable 2.2.
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
7 + 7 = ?
Subscribe to this entry?

 
 [2001-03-08 20:07 UTC] robsta at bigfoot dot com
Also running Zend optimiser 1.0. Removing the optimiser makes no difference to the outcome.
The problem should hopefully be outlined in the cut and paste of the code below. There are no other operations occurring on any of the instantiated objects at the time:

-----------------------------
$crList  = $this -> getLinkedCRs (); // method returns an array of instantiated objects (CRRecord class).

foreach ($crList as $cr)
{
  if (!$cr -> okToClose ()) // method returns a Boolean, and sets a Boolean data member in the cr object.
  {
    return false;
  }
}
   
foreach ($crList as $cr)
{
  // Previously set Boolean data member now appears to no longer be set.
  $cr -> okToClose (); // Inserting the method call in again here ensures that the following method call works.
  $cr -> close ($changeBy); // method operates only if the previously set Boolean data member is true.
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-29 06:14 UTC] stas@php.net
Could you please describe in more detail what happens and
what the problem is?

Also note that when you are using foreach, it operates on
the copy of the data, not the data itself. So if you modify
it, the change won't be made in the original data.
 [2001-03-29 10:07 UTC] robsta at bigfoot dot com
Ah of course :o)
Looking at the code again if I make the first foreach loop become:

foreach ($crList as $index => $cr)
{
  if ($cr -> okToClose ())
  {
    $crList [$index] = $cr;
  }
  else
  {
    return false;
  }
}

Then as you say the changes to the copy of the object are 'absorbed' back into the list. Many thanks for that, this isn't a problem after all :o)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 06:01:26 2024 UTC