Proposal for fixing PHP namespacing in Drupal 8

Track: 
Coder
Experience: 
Intermediate

The lack of proper namespacing for PHP functions and classes is causing lots of problems for Drupal:

  • A PHP library could redeclare a function or class that already exists in Drupal - causing PHP to abort.
  • In a magic function / hook implementation there is ambiguity of where the module name ends and the hook name begins, e.g. views_comment_load() - is the hook 'comment_load' or 'load'?
  • Modules can inadvertently implement a hook for some other module.
  • Multiple modules can 'invent' the same hook, expecting it to do different things.

These problems can be fixed through a combination of 2 methods:

See http://bluedroplet.com/blog/proposal-fixing-php-namespacing-drupal-8

Discussions about namespacing are ongoing, so the proposal may be different by Drupalcon.

Older discussions: http://drupal.org/node/867772 http://drupal.org/node/548470

Intended audience: 

Anyone who writes Drupal code.
Core developers.
Crell. (specific enough?)

Questions answered by this session
Question 1: 
How is lack of PHP namespacing screwing up Drupal development?
Question 2: 
How do PHP 5.3 namespaces work?
Question 3: 
How can PHP namespaces be utilised for Drupal core and Drupal modules?
Question 4: 
What is a better system for magic function / hook implementation naming?
Question 5: 
How can we go about implementing these changes? To what extent can it be automated?
3.57143
Your rating: None Average: 3.6 (21 votes)

Diamond Sponsors

 
Palantir.net
VPS NET

Platinum sponsors

 
workhabit
Trellon

Gold Sponsors

 
Chapter Three
HotDrupal.com
Drupal Connect
Duo
Treehouse Agency
NorthPoint
Microsoft