Opinions on PHPDOC as a documentation aid

Opinions please

PHPDOC has been around as a documentation standard for a while and is obviously based on JavaDoc. The ability to generate pages of HTML documentation is obviously nice but it does have the downside of producing documentation that is not directly tied in to the source code - over time the source code can change but the documentation does not (unless you remember to regenerate it).

The other aspects are

1) The visual appearance of the comments
2) The need to be accurate in producing the comments in a given format

I have always found the format of the comments too visually impactive - the comment takes over and you loose sight of the code  very quickly, for instance

     protected $email;       // Contact email address
     protected $name;      // Customer's name

as opposed to
      * Contact email address
      * @var string
     protected $email;

      * Customer name
      * @var string
     protected $name;l

Even with just two of these, the  declaration between the comments is much more visually invisible and when you have a dozen such declarations and comments you soon lose sight of the working code in the sea of comment code

Something deep in my programmer's soul tells me that I should be producing code that can be automatically documented whilst the pragmstist in me shouts that no one ever reads documentation - they read the code instead.

None of the code at present is available for public release so this would be an internal exercise and decision. I can easily enough transform our existing code libraries over to the PHPDOC format by use of a small program and regexes, but should I bother? I'm not convinced so I'd appreciate opinions.

LVL 34
Beverley PortlockAsked:
Who is Participating?
HackneyCabConnect With a Mentor Commented:
Well, I have to say honestly that it sounds like you've made your decision already. But, for what it's worth, I'm very happy with phpDocumentor:


I use Netbeans as an IDE for PHP, and with a little configuration you can run phpDocumentor on your entire project just by hitting F6. And as for the look of the HTML produced, you can pick from one of several styles, or (if you're really determined to have a certain look) create your own transformation template. Also, in Netbeans (with the PHP mode) your bulky phpDoc comment blocks do you another favour: by declaring the type of a declared variable (type string in the case of your examples, but it's mostly useful when declaring objects) Netbeans knows which class a variable belongs to, and it can show you what methods are available to an object of that class. Very handy.

As for people reading code rather than documentation, I couldn't agree less. Reading code is great for a script of two or three linear files, but once you're using OOP and you're calling the API of a dozen or so classes, you don't care about the code, you just need to know the method signature (what a method is for, what parameters it takes, and what it returns), and the sort of documentation produced by phpDocumentor is perfect for this.

I will admit that combining a tutorial document into the HTML produced by phpDocumentor is a faff (you have to write the documentation in DocBook format) but to have the option to package API and tutorial together is nice. Also that I don't use phpDocumentor to document page scripts (which simply make calls to classes and are as short as possible), where standard comment lines are adequate.
Beverley PortlockAuthor Commented:
"Well, I have to say honestly that it sounds like you've made your decision already."

No I haven't.

I'm trying to decide if it is worth the bother of applying it retrospectively to 70,000 lines of library code. Setting aside the effort involved, what will I have at the end of the exercise other than a set of documentation? At present each class resides in it own source file with the same name as the class and the files are grouped by folder. We use Eclipse rather than netbeans and the IDE has a list of all methods and we use standard naming conventions as far as possible.

I guess what I'm aiming at here is what other benefits accrue from PHPDOC? Are there any others? It seems sensible to use a documentation standard if one exists, especially an automated one, but will it get me anything more than a prettily formatted pile of paper in a ring binder that will never be opened?

Does anything else out there utilise PHPDOC comments for any other purposes? When I lived in the IBM midrange world, a comment attached to data definitions and the like would travel throughout the system and pop up in utuilities and screen layout programs, etc. Commenting things was practically a necessity.

Beverley PortlockAuthor Commented:
I guess we will just have to have a debate internally.

Thanks for your input HackneyCab
Beverley PortlockAuthor Commented:
FYI - After an internal discussion the developers have decided to adopt PhpDoc as an internal standard and the existing code base will be automatically converted over.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.