Strategy for developing namespaced and non-namespaced versions of same PHP code

前端 未结 9 2028
时光取名叫无心
时光取名叫无心 2020-12-23 13:43

I\'m maintaining library written for PHP 5.2 and I\'d like to create PHP 5.3-namespaced version of it. However, I\'d also keep non-namespaced version up to date until PHP 5.

相关标签:
9条回答
  • 2020-12-23 14:23

    I haven't tested this on my own, but you may take a look on this php 5.2 -> php 5.3 conversion script.

    It's is not the same as 5.3 -> 5.2, but maybe you will find some useful stuff there.

    0 讨论(0)
  • 2020-12-23 14:25

    What I did, with a large codebase that used the underscore naming convention (among others), and require_once a whole lot in lieu of an autoloader, was to define an autoloader, and add class_alias lines in the files defining aliases to a classes old name after changing their names to be nice with namespaces.

    I then started removing require_once statements where execution was not dependent on inclusion order, since the autoloader would pick stuff up, and namespace stuff as I went along fixing bugs and so on.

    It's worked quite well so far.

    0 讨论(0)
  • 2020-12-23 14:26

    I don't think preprocessing the 5.3 code this is a great idea. If your code is functionally identical in both PHP 5.2 and 5.3 with the exception of using namespaces, instead of underscore-separated prefixes, why use namespaces at all? In that case it sounds to me like you want to use namespaces, for the sake of using namespaces..

    I do think you'll find that as you migrate to namespaces, you will start to 'think a bit differently' about organizing your code.

    For this reason, I strongly agree with your first solution. Create a fork and do backports of features and bugfixes.

    Good luck!

    0 讨论(0)
提交回复
热议问题