As we all know, probably the most annoying aspect of these problems is that the various “duplicated” bits of code are often not quite the same.
PHP’s biggest weakness, in my opinion, is also a fundamental aspect of its design: “code and data are intermingled.” Logic is scattered willy-and-yon among the presentation and is usually completely governed by it. I have turned a lot of PHP modules into Template::Toolkit files, but it was never, ever easy. You basically are re-writing the damn thing . . . basically, from scratch. But sometimes you just can’t make a silk purse.