How do I generate UML diagram based on existing classes in PHP?
-
3I don't work with PHP anymore, so I don't have code to actually test out. When I posted this none of the initial answers were doing enough, but a lot has changed since then. I was working with PHP 5.2, and it is now PHP7 these days. – Jeffrey04 Sep 25 '17 at 07:54
11 Answers
There's also the PHP UML tool available from pear.
PHP_UML:
- Can generate UML/XMI files in version 1.4, or in version 2.1 (logical, component, and deployment views)
- Can generate an API documentation in HTML format
- Can generate PHP code (code skeleton) from a given XMI file
- Can convert UML/XMI content from version 1.4 to version 2.1
Install it on the command line via:
$ pear install pear/php_uml
(This used to be $ pear install pear/php_uml-alpha
but the package has since gone stable.)
Generate your xmi:
$ phpuml -o project.xmi

- 3,804
- 3
- 29
- 31
-
2for some reason, pear.com doesn't like that link without a trailing slash: http://pear.php.net/package/PHP_UML/ – Stephen Fuhry Jan 08 '10 at 16:13
-
1@Stephen, yeah I noticed that too! If you click the link, it gives you a 404, but if you select the address bar and press enter, it works. – nickf Jan 16 '10 at 14:01
-
1A few years later command is now `pear install PHP_UML-1.6.1` (see http://pear.php.net/package/PHP_UML/download/All or http://pear.php.net/package/PHP_UML/) – Ben Nov 22 '13 at 04:27
-
Installed 1.6.2 version, but getting error: 'phpuml' is not recognized as an internal or external command, – Dariux Jul 24 '16 at 20:19
-
4
-
@DevWL: That's not all that surprising - the author/maintainer might be happy receive assistance in getting it to work with PHP 7, if you're feeling generous. – kguest May 11 '17 at 21:29
I strongly recommend BOUML which:
- is extremely fast (fastest UML tool ever created, check out benchmarks),
- has rock solid PHP import and export support (also supports C++, Java, Python)
- is multiplatform (Linux, Windows, other OSes),
- is full featured, impressively intensively developed (look at development history, it's hard to believe that such fast progress is possible).
- supports plugins, has modular architecture (this allows user contributions, looks like BOUML community is forming up)

- 892
- 1
- 9
- 22
-
6The web page for BOUML now states: "CAUTION: Due to the continuous license violations, attacks and insults from people of wikipedia [...], I have decided to stop work on Bouml except to fix bugs." – MPV Jul 06 '11 at 10:04
-
@MPV - i am able to install it from the Ubuntu Software Center – Imran Omar Bukhsh Jan 14 '12 at 10:58
-
1"[December 18, 2011] Downloads are suspended until further notice" from their official web site. [http://bouml.free.fr/download.html](http://bouml.free.fr/download.html) - this is because I needed a version for Win7. I imagine it may still be available from Ubuntu repositories - need to check – Val Redchenko Feb 07 '12 at 12:25
-
@ValRedchenko BOUML 5.0.1 Released on **February, 22th 2012.** Its still available. – Shiplu Mokaddim Mar 26 '12 at 09:00
-
5Version 6.1 released **September 23, 2012**. Appears development has picked up again. No notice about slowing down, stopping, etc. http://www.bouml.fr/historic.html – Andrew Ensley Oct 04 '12 at 19:02
-
1The documentation is horrible, I never figured out how to generate a single diagram. Maybe you can write a tutorial on this – unifreak Apr 18 '19 at 05:35
phUML
phUML is fully automatic UML class diagramm generator written in PHP, licensed under the BSD license. It is capable of parsing any PHP5 object oriented source code and create an appropriate image representation of the oo structure based on the UML specification.
./phuml -r /var/www/my_project -graphviz -createAssociations false -neato out.png

- 44,706
- 42
- 157
- 243

- 10,437
- 2
- 40
- 57
-
requires SVN/subversion to download and doesn't really say what the license of the source code is, but it looks good! yah I would be careful at looking at the source code there's absolutely no license on it and the only readme is on the site I think – Jan 27 '14 at 18:04
-
The license is linked right there in the project's website sidebar, under the author, Creative Commons: http://creativecommons.org/licenses/by-nc-sa/3.0/ – Anthony Hatzopoulos Jan 28 '14 at 03:54
-
that's the license for the content of the site, the LICENSE for the project *must* be included with the project itself. – Jan 29 '14 at 01:55
-
4I sent an email to the author, Jakob and he responded with an update to the repository with a clear and cut [3-clause bsd License](https://github.com/jakobwesthoff/phuml/blob/master/LICENSE) – Anthony Hatzopoulos Jan 31 '14 at 02:27
-
I downloaded this and got it to work after a bit of tinkering. Was really quite nice, except I can't get the associations to work, but I'm sure i'll figure it out. Nice, simple. No GUI though, but not that big of a deal. – Impulss Feb 05 '14 at 05:38
-
I like the `dot` output style which places all objects linearly instead of star (neato) shape with associations on the entire project class folder: `~/phuml/app/phuml -r ~/path_to_your/classes/ -graphviz -createAssociations true -dot ~/output_folder/test_dot.png` – Anthony Hatzopoulos Feb 05 '14 at 16:35
-
The original by Jakob Westhoff has been removed from his site; I found a fork at https://github.com/greenantdotcom/phUML – Mikko Rantalainen Mar 06 '14 at 10:27
-
@MikkoRantalainen The official github repo is https://github.com/jakobwesthoff/phuml (I've updated the answer) – Anthony Hatzopoulos Mar 06 '14 at 20:30
the best (Windows) software i have found to do PHP and UML is Sparx Systems Enterprise Architect. besides a pletora of features, it supports the following for PHP:
- Reverse engineer object oriented PHP into UML class diagrams
- Generate PHP class definitions from UML class diagrams
- Synchronize changes made in a UML class into the corresponding PHP class definition
- Synchronize changes made in a PHP class definition into the corresponding UML class
- Create UML sequence diagrams to show what PHP classes use and how they are used
- Produce detailed documentation of your PHP code in standard RTF and HTML format
- Perform code engineering on models to generate base PHP pages.
not free ($199), but definitely worth the money.

- 58,560
- 8
- 81
- 72
-
1Wow, that's a really useful and professional program indeed, thanks for the tip!! I just tried the UML class diagram generating with the Sparx EA's reverse engineering method from PHP source code, and it worked like a charm, I was shocked how fine this worked. :D As our projects are growing bigger and bigger, and we create more and more objects, it's getting harder to keep an eye on our own code, but it's a great help in it, as it generates the UML diagrams the right way (of course, maybe exceptions may occur) AFTER we finished the code. This even helps to simplify relations between objects. – Sk8erPeter Jun 09 '11 at 01:17
-
@ax - I'm a newbie, and I get a bit lost in their list of features (under "compare editions"). What would be the name of the feature that allows me to enter PHP code (or link to PHP files), and get a diagram in return? Trying to figure out which version I might need. – JDelage Jul 31 '12 at 22:45
Have you tried Autodia yet? Last time I tried it it wasn't perfect, but it was good enough.

- 330,807
- 53
- 334
- 373
-
i tried autodia but somehow i cant generate accurate class diagram (php5) – Jeffrey04 Dec 26 '08 at 10:09
There's also php2xmi. You have to do a bit of manual work, but it generates all the classes, so all you have to do is to drag them into a classdiagram in Umbrello.
Otherwise, generating a diagram with the use of reflection and graphviz, is fairly simple. I have a snippet over here, that you can use as a starting point.

- 115,121
- 27
- 131
- 155
Here's how I did it (directly from code to PDF drawing without manual drawing of anything):
- Use BOUML for "reverse engineering PHP code" [sic] to extract the class model (BOUML is available from "universe" repository of Ubuntu). I seriously recommend BOUML for this step because it's really fast compared to many other programs I have tried. In addition, it seems that BOUML seems to extract the model correctly (for the parts that BOUML even tries to extract).
- Use BOUML to export model as XMI 1.4 file
- Use ArgoUML to import said XMI file (you can use webstart version for this step)
- Export XMI from ArgoUML (I don't know which XMI version/variant the output is but it is not the same result as the output from BOUML. The argouml-graphviz cannot handle XMI file directly from BOUML).
- Use argouml-graphviz to convert ArgoUML exported XMI file to dot format (you may need to use saxon instead of xsltproc to get it work due to use of XSLT2)
- Use dot or fdp or sfdp to render the class diagram.
Here's an example of suitable command line for using fdp to output PDF diagram (assuming that dot file generated by argouml-graphviz XLST processing is saved as xmi-model.dot):
fdp -Tpdf -Gmaxiter=1000 -Gmindist=0.5 -Gpackmode=node \
-Eweight=0.05 -Elen=1.0 -Eminlen=1.0 -Gsplines=true \
-Goverlap=false xmi-model.dot -oxmi-model.pdf
As an alternative you could try PHP_UML or php2xmi instead of BOUML for doing the "reverse engineering" part. I haven't yet tried that.
(I'm using the phrase "reverse engineering" because it seems that UML people are using those words when they mean extracting class and method information from the source code. I would personally interpret those words as extracting information from executable binary file or captured raw wire data.)
If you prefer drawing the class diagram by hand (instead of using computer to do all the drawing), you can use either BOUML or ArgoUML for the drawing. Using the "reverse engineered" data via BOUML will help in that case.

- 14,132
- 10
- 74
- 112
If you are looking to generate UML easily from your existing PHP Classes you might want to consider PHPStorm 3.0 IDE. It does a good job of replicating existing code into UML.
Have a look at the PHP Storm feature list.

- 9,408
- 18
- 74
- 116

- 690
- 7
- 19
In theory you can use PhpStorm to visualise your classes using UML. The generation is not really great but you can effectively refactor stuff and again, at least preview parents, implementations, constants, attributes, methods and their visibility in a nice way.
Situation
I want to visualise a communication between already existing components to a colleague.
Process using PHPStorm
https://blog.jetbrains.com/phpstorm/2017/09/uml-diagrams-in-phpstorm-2017-2/
Advantages
- Nice UI, final diagram.
- Able to refactor code from a diagram.
- Able to add notes.
- The class diagram symbolises private/public properties, constructors, methods nicely.
Disadvantages
- No support for PHP 7.
- Painfully to use. Can't resize the generated boxes.
- When adding a new relation, the previous ones get randomly lost :O wtf?
- Restarting PhpStorm destroys the diagrams
- Changed my mind, impossible to use relations
Result
Anyway, after some painful hour of work I was only able to generate unrelated boxes and had to use additional program to link relations. Really bad. But I believe once they make it work properly it will be a great feature because as the code changes, the diagrams would be automatically updated!
For now, don't use PhpStorm for UML diagrams.

- 7,766
- 10
- 65
- 75
You can use Visual Paradigm for UML. This might not be the best paid (it's US$699) product, just as an option if anyone would like to try. It can create class diagram from PHP and vice versa, and not only PHP, there's a bunch of language you can choose such as C#, C++, Ruby, Java, VB.NET, Python, Objective C, Perl, etc. There's also a trial you can check on.

- 7,179
- 1
- 34
- 32
-
I try this tool, on Visual Paradigm is called "Instant Reverse" and is pretty amazing, I use a module from a controller that I built on Symphony and the UML Class diagrams was the expected! This time I am lookgin for an open source service, the main reason is for "scaling" and provide non interaction with the Dev team, I wanna to implement this documentation process as a job on a CI pipeline (maybe I will face many challenges). – Franco Gil Aug 04 '23 at 16:27
Well to be honest, first and foremost you shouldn't generate UML model from code, but code from UML model ;).
Even if you are in a rare situation, when you need to do this reverse engineering, it is generally suggested that you do it by hand or at least tidy-up the diagrams, as auto-generated UML has really poor visual (=information) value most of the time.
If you just need to generate the diagrams, it's probably a good thing to ask yourself why exactly? Who is the intended audience and what is the goal? What does the auto-generated diagram have to offer, what code doesn't?
Basicly I accept only one answer to that question. It just got too big and incomprehensible.
Which again is a reason to start with UML in the first place, as opposed to start coding ;) It's called analysis and it's on decline, because every second guy in business thinks it's a bit too expensive and not really necessary.

- 51
- 5
-
7True, but life is a more complicated than some principles, which are wise to use. You might need to compare actual code against the original UML diagram, or analyse someones code or some some code, which was implemented without UML diagrams. – D.A.H Jul 21 '15 at 13:13
-
3Disagree. Great value gained from visualizing a code base/module with a diagram. Code is like street directions, but with too many directions sometimes one might find a map useful. – Basil Musa Apr 23 '17 at 13:41
-
1Most UML drawing programs have such a bad UI that it's *faster* to write the code and generate the UML diagram automatically, even if you then throw away the code that you used to generate the diagram... – Mikko Rantalainen Mar 29 '18 at 09:46