I'd like to suggest that we introduce PHP namespaces for XH 1.7. Mainly I have in mind to introduce the XH and Filebrowser namespaces, and to adapt the autoloader for general loading of properly namespaced classes. I'm having only humble experiences with namespaces in PHP, but it appears to be only beneficial to put all classes in a proper namespace (instead of prefixing them with a separating underscore as it's done since CMSimple_XH 1.6). That allows to omit the namespace inside the same namespace. For now there are only a few places where that would make a difference, but I'm quite sure there'll be more in the not too distant future (think about type hints, which would make sense as soon as we pass objects as function arguments, what's currently not done due to the value semantics of PHP 4 objects). For example, currently we have:
Code: Select all
class XH_PageDataRouter
{
// ...
public function __construct($h, $pageDataFields, $tempData, $pageData)
{
$this->model = new XH_PageDataModel(
Code: Select all
namespace XH;
class PageDataRouter
{
// ...
public function __construct($h, $pageDataFields, $tempData, $pageData)
{
$this->model = new PageDataModel(
To keep backward compatibility, we could adjust the autoloader to automatically create a class_alias for the underscore convention for each class that is loaded.
I have some doubts that it makes sense to put the XH_* functions into a namespace. The main problem is that we would have to add aliases for several of them for backward compatibility. Unfortunately, there is no function_alias() or something like that, so we'd actually need to write wrapper functions. This appears to have more drawbacks than advantages, especially as I think it is actually useful to structure the existing functions differently in the future (not so much for XH 1.7). If that's going to happen, we would be left with a big bunch of compatibility function wrappers.
Thoughts?
PS: Of course, we should add use XH; to all relevant core and internal plugin files, if we're going to introduce the namespace.