UML & PHP

Thie content or the technology discussed here is EXPERIMENTAL only

A Webel zone dedicated to attempts to interpret PHP as UML™.

The image below shows an attempt to represent a simple PHP system (some scripts developed by Webel for client for bulk migration and administration of Drupal™ SimpleNews subscription data) in UML™ by importing the XMI file generated by the PHP_UML tool into the MagicDraw™ UML tool.

Unfortunately - because PHP does not enforce typed Properties - it can very difficult to manage/reverse the Relationships between Classes ! PHP_UML uses an introduced DataType 'mixed' as a catch-all for any TypeAssociations. Instead Dependencies and Usages have been used.

Angry The process shown requires so much intervention that the (possibly enormous) benefits of obtaining an associative UML™ representation are largely undermined !

Note also that Visual Paradigm and Enterprise Architect both claim to reverse-engineer PHP to UML, and Enterprise Architect claims to be able to also generate PHP from class diagrams, and supports a degree of synchronised engineering. However if you look closely at the EA examples you'll see that in fact there is a contrived "links to / links from" system used to represent Relationships between Classes, instead of consistent Associations with Property ends !

PHP5 introduced type-hinting of object parameters to functions (and since PHP 5.1 also for array parameters), however this does not help reverse engineering to UML much, since the PHP class variables (if considered the equivalent of Properties) are not typed, and likewise function return values are not typed (so one can't interpret accessor/mutator methods as typed property methods).

Cool I suggest that PHP could be be improved by the introduction of optional type-hinting for variables of classes, either using explicit type notation, or by using @type annotations in comments, which could be interpreted by UML reversing engines for PHP.

However, none of this helps much if one wishes to reverse engineer very loosely typed legacy PHP systems with copious use of mixed types like Drupal™ !

UML & PHP
Visit also
randomness