Notes on using PHP namespaces

  • Stay clear of class names that are PHP keywords. Example: "F3_Package_Controller_New" becomes "New" when adding namespaces, "F3_Blah_View_Empty" becomes "Empty", ... Rule: all reserved keywords are disallowed. But using "EmptyView" or "DefaultController" is cleaner style anyway!
  • Watch out for that global namespace! Type hints like "Exception $e" will break - the current namespace is applied first, no fallback is applied for classs or interfaces! Use "\Exception $e" in cases like that. This includes instantiations of PHP internal classes as well, e.g. DateTime, ArrayObject, ... The same is true for any other non-namespaced classes you use in your code (look at the Lucene or PHPUnit parts of the code).
  • Always use the fully qualified name (for now). I.e. even in a class always type the full name, as before, just with \ instead of _. This avoids problems with ambiguity, class loading, name resolution and changing the world climate until we have a better understanding of
    a) best practices on using namespaces
    b) how to refactor things if names are unique only if you know about the namespace of their scope
  • DEV3 now complains about syntax errors in TypoScript2 files as it does not yet know about the new syntax for component names.