{"id":1450,"date":"2018-01-19T19:22:51","date_gmt":"2018-01-19T19:22:51","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/how-to-document-your-php-classes-page-3\/"},"modified":"2018-01-19T19:24:48","modified_gmt":"2018-01-19T19:24:48","slug":"how-to-document-your-php-classes-page-3","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/how-to-document-your-php-classes-page-3\/","title":{"rendered":"How To Document Your PHP Classes Page 3"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Stefano Locati<\/div>\n<div class=\"\">on August 25, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nI decided to test this script on its own PHP source and I found it  working partially: it could just generate the<br \/>\ndocumentation of the classes (neatly formatted), but not the summaries. I don&#8217;t know if this happens just on my<br \/>\nmachine, but it just stopped with a core dump (PHP 4.0 pl2 on a RedHat 6.2) when trying to generate the summaries.<br \/>\nSupposing you&#8217;ve a PHP executable installed in \/usr\/local\/bin the syntax for calling it is (to have some results<br \/>\nI had to give full paths of both the php files and the output directory) <\/div>\n<div class=\"example\">\n<pre>\n.\/phpautodoc &lt;php_files&gt; -o &lt;output_dir&gt;\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\n<a href=\"http:\/\/sourceforge.net\/projects\/phpdoc\">phpdoc<\/a> is a tool to maintain documentation about PHP files<br \/>\non the web and it is best suited for distributed development efforts. The documentation gets written into a<br \/>\nMySQL database; after installing it you can document your classes by adding them using a web interface. This<br \/>\nis really interesting but is a way to maintain a low level documentation separatated from source code which<br \/>\nas I said it&#8217;s not very convenient.<\/div>\n<h2>A General Purpose Tool<\/h2>\n<div class=\"articlePara\">\nAfter experiencing some frustration trying all these tools without much success and until a standard solution is<br \/>\nproposed by the <a href=\"http:\/\/pear.php.net\/\" target=\"_blank\">Pear Project<\/a>, I found a working tool completely<br \/>\nunrelated to PHP in the <a href=\"http:\/\/publicsource.apple.com\/\" target=\"_blank\">Open Source Projects at Apple<\/a> website. The<br \/>\nname of the project is <a href=\"http:\/\/publicsource.apple.com\/projects\/headerdoc\/\" target=\"_blank\">HeaderDoc<\/a>. As the website<br \/>\nstates <i>HeaderDoc is a tool for generating HTML reference documentation for comments of C or C++ header files.<br \/>\nIt is written in Perl for easy portability. Similar to JavaDoc, it allows developers to easily document their<br \/>\ninterfaces and export that information into HTML.<\/i><\/div>\n<div class=\"articlePara\">\nYes, you&#8217;ve read well, HeaderDoc supports just C and C++. No other languages, but it happens that, unlike<br \/>\nJavadoc, it relies mostly on tags written inside comments and so can works well for PHP too with minor<br \/>\nmodifications (I will explain later). The tags are Javadoc-like, some examples of Headerdoc tags are<br \/>\n@class, @function and @var.<\/div>\n<h2>Documenting A Class<\/h2>\n<div class=\"articlePara\">\nOk so let&#8217;s dive into details now. First let&#8217;s take a look to how a class can be documented.<\/div>\n<div class=\"example\">\n<pre>\n\/*! @class BagItem\n    @abstract An item in the shopping bag - it is a shopitem with quantity\n    @discussion A BagItem object may be constructed without previous instantiation \n\tof neither ShopItem nor Product\n*\/\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\n<img decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/stefano20000824_class.gif\" alt=\"Documentation of a class\" border=\"1\"\/><\/div>\n<div class=\"articlePara\">\n<i>Documentation of a class. On the left frame it is possible to choose a method of the class.<\/i><\/div>\n<div class=\"articlePara\">\nThe first thing to notice is that the style used to open comments is not exactly like Javadoc comments<br \/>\n<code class=\"example\">\/**<\/code> (a slash and two asterisks), but is instead <code class=\"example\">\/*!<\/code> (a slash, an asterisk<br \/>\nand an exclamation mark). Tags are different too, but they work in a similar way.<br \/>\nFor example the first tag is the <code class=\"example\">@class<\/code> tag which is used to document a class,<br \/>\nthis tag is followed by the class name. The next tag is the <code class=\"example\">@abstract<\/code> tag which is<br \/>\nan optional tag describing in a few words the meaning of the class, while the <code class=\"example\">@discussion<\/code><br \/>\ntag is another optional tag used for a more in depth discussion. Of course it&#8217;s up<br \/>\nto you to decide wether to write everything in the <code class=\"example\">@discussion<\/code> tag or use the<br \/>\n <code class=\"example\">@abstract<\/code> too, but remember that in general, the more specific tags<br \/>\n  you use, the better the results are.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"stefano200008244658.html?page=2\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"stefano20000824.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"stefano200008244658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">3<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"stefano20000824fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"stefano20000824af4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"stefano20000824fdb0.html?page=4\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>By Stefano Locati on August 25, 2000 I decided to test this script on its own PHP source and I found it working partially: it could just generate the documentation of the classes (neatly formatted), but not the summaries. I don&#8217;t know if this happens just on my machine, but&#8230; <a href=\"https:\/\/phpbuilder.com\/how-to-document-your-php-classes-page-3\/\" class=\"readmore\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1450","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1450"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"predecessor-version":[{"id":2238,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1450\/revisions\/2238"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}