each deprecation

Created by: Administrator, Last modification: 18 Jan 2019 (15:17 UTC)

One of the items on the todo list is to replace 'each(' with foreach, as a majority of developers decided each should be deprecated. That the vote was not unanimous is at least encouraging that my own view is there was no strong case to do so, but we now have to live with the result of that vote. One of the problems as usual is just when will the key libraries be updated or does one have to make ones own corrections to be on the safe side.

The stackoverflow questions while-each-is-deprecated-foreach-replacement-takes-a-lot-more-time probably sums up the situation nicely, and many of the structures in the bitweaver code base are based on similar extended code bases. With some 433 references to ' each(' in the code, working through them and identifying which third party library they come from is not a 5 minute job.

The basic conversion does follow a legacy standard, with a while/each loop being replaced by a matching foreach loop, but where the while loop is expanded to cover other actions the problems highlighted on stackflow require a deeper investigation of the code.

The legacy style loop is based on
while (list($key, $val) = each($array)) { echo "$key => $val\n"; }

And this maps to the now prefered
foreach ($array as $key => $val) echo "$key => $val\n"; }

OK this is not looking quite so bad now, after side-lining the commence packages I'm down to 96 instances and the first few all follow the above pattern so I'll leave the commerce sites on 7.0 for the time being until someone else deals with them.

TODO ... add other code changes as they are identified.