This is rather subjective, I think. Most people would say that PHP has been reasonably backwards-compatible. In that a script written for version 4 would mostly function on version 5. There are various settings and warnings you can enable which will notify you about potential problems (e.g. E_STRICT
and E_DEPRECATED
warning levels).
However, there's probably a number of people who have bitten by the odd compatibility-breaking changes between versions (here's a list for PHP 5.3 for example).
Edit To answer your direct questions:
Developers who work on PHP is it easy to migrate from version to version?
It's not particularly difficult. Again, this is subjective and depends on what you consider "easy". If you're moving from version 4 to version 5 (say) then that's more difficult than 5.1 to 5.2. But it also comes down to your question #4. Version 5, for example, introduced pretty major updates to the object model so while you can still run a script written for version 4 largely unmodified, it won't be using the PHP 5 class system and so might not be considered "idiomatic".
Are there any extensive compatibility issues, forward or backward?
Extensive? No. Scripts written for version 3 will run largely unmodified on version 4 and scripts written for version 4 will run largely unmodified on version 5. Going the other way (forwards compatibility) is a totally different story, and no language (that I know of?) ever attempts to be forwards compatible. The huge number of additional features makes it difficult to run a script designed for 5.3 even on version 5.2 (to be honest though, 5.3 was almost a major-version update).
Does your project stick to a particular version till the end?
For the most part, yes. But most of the "projects" I work on are actual websites. If I was working on a framework or library then updating it to work on newer versions of the runtime would be a consideration.
Does the programming style ,approach change from version to version?
Yes. Version 5 updated the object model to such large degree that (idiomatic) PHP 5 code looks quite different to (idiomatic) PHP 4 code. It's still basically the same ($variable
, <?php ?>
tags etc), but structurally it might look quite different.
Personally, I tend to use a framework (currently I'm liking CakePHP quite a lot) and they will typically introduce their own style and approach over and above the basic PHP engine. I'll often switch frameworks for different projects, too, depending on circumstances and what's best for the job (for example, I used to like Drupal, but it now feels too "PHP4-ish" for my tastes)
If you had to get started on PHP to contribute to a project built earlier versions, would learning the latest version be counterproductive towards this aim?
No, it wouldn't be counter-productive, but you have to remember that older versions basically have "missing features" compared to newer versions. For example, I really miss the better built-in DateTime
class when I go from PHP 5.3 to 5.2 and older...
In Summary
Personally, I think you're putting too much emphasis on "compatibility" here. I write mostly Python and C++ code at work, and I also dabble in Java for Android development and even a bit of ASP.NET every now and then. Frankly, switching between PHP4 and PHP5 is almost trivial by comparison.