[Work in Progress] Namespaces, Autoloading, Class-based Constants

Replaces #255

I'm sorry I've had to squash all the work together into a single commit to get rid of all the back-and-forth.

The squash also includes
* Restored composer.lock file
* Restore 644 file mode.
* Removed whitespace at end of line.
* Various coding guideline fixes.

This still needs more work, e.g. merge of php5 into this branch.