Would be great if this could get a little love. I am trying to package PHP and one error I get comes from this script.

There seems to be a logic error -- as it continues to remove what it is supposed to be installing.

I have added to the bug - environment values at start/stop of script - AND a two-line HACK I added to get result needed.
Since I do not understand/know what the starting point should be, hard to really fix the insides.