6.0.0-git
2019-05-27

[#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 2007-03-08 (4463 days ago)
Due
Updated 2007-06-01 (4378 days ago)
Assigned 2007-03-08 (4463 days ago)
Resolved 2007-06-01 (4378 days ago)
Milestone
Patch No

History
2007-06-01 14:55:42 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.
2007-06-01 14:38:49 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...
2007-06-01 09:09:13 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')

}


2007-06-01 09:05:41 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.


2007-04-13 15:26:40 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.
2007-04-13 15:17:04 Chuck Hagenbuch State ⇒ No Feedback
 
2007-03-09 11:24:38 Jan Schneider Comment #5 Reply to this comment
But this loop doesn't even use references.
2007-03-09 08:38:03 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.
2007-03-08 20:18:30 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?
2007-03-08 07:54:17 wrobel (at) pardus (dot) de Comment #2 Reply to this comment
s/the driver would/the share driver would/
2007-03-08 07:53:18 wrobel (at) pardus (dot) de Comment #1
Type ⇒ Bug
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Summary ⇒ foreach with references in the tasklists.inc template
Queue ⇒ Nag
New Attachment: nag-templates-tasklists-tasklists.inc_foreach-with-references_20070308.patch Download
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