My first thought is that patching the foreach may not be the most straightforward solution due to the huge can of worms it can open. If that is the case I would appreciate any insight as to where else I shoudl be looking. I assume someone working on Smarty can come up with a better way to dynamically handle this or explain to me why it's not actually a bug. I will explain in php code and then show how that seems to me to apply to how Smarty should handle the foreach loop.įoreach ( $fields as $this_view_section_name => $these_fields ) ++ \n" The problem arises in a Smarty foreach loop, but the testing I did first in php. New also in PHP5, objects are passed by reference by default - so it shouldn't matter in a foreach loop on an array of objects whether or not the & is explicitly declared - the foreach should always work on the reference that is the object (can't find the note in the Zend reference that confirms this, but I know I read it there somewhere). When one does not put the & before the item PHP uses a copy in the loop. When you want the foreach loop to pass via reference you have to specify & before the item in the foreach loop. In the above link it is pointed out that when using a reference in a loop it has to be unset before the next iteration of the loop uses it, otherwise old data will get overwritten.Ī similar issue occurs with foreach loops in PHP5, which adds the ability to use references in the foreach loop. Posted: Wed 8:51 pm Post subject: Foreach on Objects/References (PHP5) - Objects OverwrittenĪs reported by jw at jwscripts dot com, 1 08:18, on the User Contributed Notes on the PHP manual, and as seen by others in practice, using references in loops can cause unexpected behavior. Foreach on Objects/References (PHP5) - Objects Overwritten
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |