Forum Moderators: coopster

Message Too Old, No Replies

Modeling in PHP procedural programming

UML or not

         

dbarasuk

6:11 am on Jan 21, 2010 (gmt 0)

10+ Year Member



Hello all,
I know UML is of great importance when one is developping applications in Object oriented languages.

Is UML still helpful when developping PHP/Mysql applications using the PHP procedural programming approach? How is that done?

Thank you for your reply.

dbarasuk

6:32 pm on Jan 21, 2010 (gmt 0)

10+ Year Member



Please help for this question.

CyBerAliEn

7:39 pm on Jan 21, 2010 (gmt 0)

10+ Year Member



PHP is primarily a procedural language due to its bare fundamentals: it serves the web. A user makes a request over the web, this request is interpreted and handled by PHP, and then terminates with output back to user. It is a process itself:
Request > Process > Output > Terminate

What happens in the "process" and "output" are in PHP's direct domain. There is always a clear start, and a clear end. Hence why PHP is a procedural language.

However... understand that today PHP offers object support, to a large degree. You can create classes, methods, objects, etc and manipulate them as you would any other language. The key difference between PHP and a language like C++/Java, is that PHP will take a request, execute, & terminate; while C++/Java will handle a request then execute (still running/active when done, or terminate if need be). PHP inherently lacks this simply due to environment (the internet/web; note that PHP does now support standalone compiled applications). But these are differences due to environment.

Note that UML diagrams used for other languages (Java/etc) revolves around the classes used, methods, etc (documents the objects, flow, etc). This is because it is object-oriented.

Even though PHP is procedural by nature, you can still achieve object oriented programming with PHP by doing your coding via classes/methods/etc (instead of just line by line by line).

So Java is object oriented; but PHP can be too. So, apply UML diagrams in the same manner! Document the classes, methods, processes, etc of your PHP just as you would if they were Java/etc classes/etc.

Note however, that if you setup your PHP code itself as procedural (ex: no classes, no methods; no significant use of functions to module-ize processes; etc)... then you cannot really use UML diagrams as traditionally used, because UML diagrams for software are inherently intended towards object oriented programming.

However, your code is still useful/functional, but in a procedural way. Your code is a single process, but it has many sub-processes. Suppose your code is about processing a submitted web form. Sub-processes within your code could be: (1) get form values; (2) check/validate form values; (3) process form action [modify, add, delete, etc something]; (4) display/return output/results. You can use this knowledge of the PROCESS to develop a UML activity diagram.

Overall, UML diagrams are widely used in industry to help document/plan application code. Since most professional programs do run in compiled languages like C++/Java, UML serves the purpose of documenting/planning well. But because PHP is ~solely used on the internet, and often coded by amateur/moderate programmers (loosely speaking)... UML diagrams are ~rarely employed to document/plan PHP software/code, even when the code is object oriented.

Hopefully this can give you some help and insight into your question.