6.0.0-alpha14
6/19/25

[#5086] foreach with references in the tasklists.inc template
Summary foreach with references in the tasklists.inc template
Queue Nag
Queue Version HEAD
Type Bug
State Resolved
Priority 1. Low
Owners
Requester wrobel (at) pardus (dot) de
Created 03/08/2007 (6678 days ago)
Due
Updated 06/01/2007 (6593 days ago)
Assigned 03/08/2007 (6678 days ago)
Resolved 06/01/2007 (6593 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
06/01/2007 02:55:42 PM Chuck Hagenbuch Comment #10
State ⇒ Resolved
Reply to this comment
I still don't understand how this results in not getting the right 
values for read-only share access, but I've committed it for now.
06/01/2007 02:38:49 PM Chuck Hagenbuch Comment #9 Reply to this comment
btw: PHP5 supports references in foreach, but that's out of the
question right now for Horde. Using PHP5 it can be written like this:
With PHP 5 objects aren't copied unless you clone them, so none of 
this junk is necessary...
06/01/2007 09:09:13 AM thomas (dot) jarosch (at) intra2net (dot) com Comment #8 Reply to this comment
foreach ($shares as $key => $share) {
$share->get('name')
}
btw: PHP5 supports references in foreach, but that's out of the 
question right now for Horde. Using PHP5 it can be written like this:



foreach ($shares as $key => &$share) {

$share->get('name')

}


06/01/2007 09:05:41 AM thomas (dot) jarosch (at) intra2net (dot) com Comment #7 Reply to this comment
Here's the root of the problem: Let's say you have an array of 
references to Horde_Share objects named $shares. When you now process 
the array via



foreach ($shares as $key => $share) {

$share->get('name')

}



it creates a copy of the share object if you access it like this.



Here's the proper fix:



foreach(array_keys($shares) as $id) {

$shares[$id]->get('name');

}



That fixed the share renaming (among other reference fixes) in mnemo, 
which are going to be submitted soon. It's also the way Turba accesses 
the shares.


04/13/2007 03:26:40 PM Gunnar Wrobel Comment #6 Reply to this comment
The problem still exists for me but I still need to investigate the 
correct source for the error and try to construct an example. I'll 
reopen it once I know more.
04/13/2007 03:17:04 PM Chuck Hagenbuch State ⇒ No Feedback
 
03/09/2007 11:24:38 AM Jan Schneider Comment #5 Reply to this comment
But this loop doesn't even use references.
03/09/2007 08:38:03 AM wrobel (at) pardus (dot) de Comment #4 Reply to this comment
The issue that I had matched what is described here:



http://www.php.net/manual/en/control-structures.foreach.php#66000



and changing the way the iteration works in that template fixed the 
problem for me. But I don't know if that is dependant on the PHP 
version. I am using PHP-5.1.6 on the development machine.



I can do further testing with the PHP version and also compare to the 
datatree driver if that is required.
03/08/2007 08:18:30 PM Chuck Hagenbuch Comment #3
State ⇒ Feedback
Reply to this comment
This doesn't make a lot of sense to me. Even if it's an array of 
references, they're not changed in either loop, and you should be able 
to loop through it more than once. Is this a difference between the 
kolab and datatree drivers, or a PHP version thing?
03/08/2007 07:54:17 AM wrobel (at) pardus (dot) de Comment #2 Reply to this comment
s/the driver would/the share driver would/
03/08/2007 07:53:18 AM wrobel (at) pardus (dot) de Comment #1
Priority ⇒ 1. Low
State ⇒ Unconfirmed
New Attachment: nag-templates-tasklists-tasklists.inc_foreach-with-references_20070308.patch Download
Queue ⇒ Nag
Summary ⇒ foreach with references in the tasklists.inc template
Type ⇒ Bug
Reply to this comment
The list of shares that is used within the tasklists.inc template is a 
list of references in my case (kolab share driver).



The use of the two foreach loops within the templates mixes up these 
refernces and once I edit a share I end up with one shares being 
listed twice and other shares missing.



In case the share array should really be an array of references the 
attached patch would fix the problematic foreach loops. In case the 
share list should not provide object references, the driver would 
probably need to be modified accordingly.

Saved Queries