I wrote a script using my local PHP 5.3 installation using the goto . Having downloaded it to my web server, I had to find that my host was still installed with PHP 5.2 and, therefore, it did not support goto . So my question is how to emulate goto functionality in the following context:
foo(); iterator_start: foreach ($array as $array_item) { switch ($array_item) { case A: foo(); break; case B:
The idea is that the array should be modified according to a set of substitution rules. After the rule is executed (which can change any number of array elements at any position, replace them, even delete them), everything should start from scratch, because the entire array can be changed in an unpredictable way (thus, recursive replacement rules are allowed as Well). The solution I use, with goto just going to the beginning of the loop after each substitution, seems very simple and even quite clean for me, but, as I said, I can not use it on my web server.
Is there any replacement for goto here, or can the same task be performed in a completely different way (preferably without changing too much code)?
Any ideas are welcome.
Polite request: Please share me with lectures on the benefits or dangers of goto here. I read PHP and the goto instruction, which will be added in PHP 5.3 , and find out about the spaghetti code and all those models that are considered malicious letters of the 1980s. The discussion of goto alleged evil has nothing to do with my question, and treating any program design as "bad style" as such is simply a dogma that does not have a place in my programming ideology.
source share