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

前端 未结 9 2085
时光取名叫无心
时光取名叫无心 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:02

    I am working on a project that emulates PHP 5.3 on PHP 5.2: prephp. It includes namespace support (not yet complete though.)

    Now, out of the experience of writing this there is one ambiguity problem in namespace resolution: Unqualified function calls and constant lookups have a fallback to the global namespace. So you could convert your code automatically only if you either fully qualified or qualified all your function calls/constant lookups or if you didn't redefine any function or constant in a namespace with the same name as a PHP built in function.

    If you strictly adhered to this practice (whichever of them you choose) it would be fairly easy to convert your code. It would be a subset of the code for emulating namespaces in prephp. If you need help with the implementation, fell free to ask me, I would be interested ;)

    PS: The namespace emulation code of prephp isn't complete yet and may be buggy. But it may give you some insights.

提交回复
热议问题