documentation code - How do you document your PHP functions and classes inline?



example generator (6)

PHPDoc, like what you've posted, is a widely accepted form of PHP documentation.

You can use Doxygen to auto-generate the docs.

Edit: In terms of generating in-line documentation in your code, I have never come across a tool that will go back and do this externally for a project. It's generally left in the realm of the IDE to generate a template while you code.

Eclipse actually does a decent job of this (it's one of the few things I like about Eclipse) and I believe Netbeans does as well. Any major IDE will likely have functionality to assist with this type of template generation.

I know there are many different standards for PHP code inline documentation. Here's what I mean by inline documentation, and please correct me if there is a better term:

/**
* This is the description for the class below.
*
* @package    my-package
* @subpackage my-subpackage
* @author     my-name
* @version    my-version
* ...
*/
class orderActions {
...

What is the best and most widely-accepted form of inline documentation? Are there any tools to auto-generate such documentation, or does it have to be done by hand?

I'm not interested in generating manuals -- I want to know how to generate the type of code commenting above, or "inline documentation."



Not sure what you code in but I have several snippets (I use Textmate) that I just add in as I'm working) I've found this ends up with the best results since I'm filling in the details instead of trusting a system to do it for me.

It's more work in the beginning but it seems to be worth it in the long run


Although I haven't fully utilized it, Doxygen looks promising for this task.

If you are familiar with the JavaDoc tool for Java, it's quite similar to that. You use the Doxygen style and then run the tool over your source files to produce documentation.



Fatal error: Call to undefined function XXX

Happens when you try to call a function that is not defined yet. Common causes include missing extensions and includes, conditional function declaration, function in function declaration or simple typos.

Example 1 - Conditional Function Declaration

$someCondition = false;
if ($someCondition === true) {
    function fn() {
        return 1;
    }
}
echo fn(); // triggers error

In this case, fn() will never be declared because $someCondition is not true.

Example 2 - Function in Function Declaration

function createFn() 
{
    function fn() {
        return 1;
    }
}
echo fn(); // triggers error

In this case, fn will only be declared once createFn() gets called. Note that subsequent calls to createFn() will trigger an error about Redeclaration of an Existing function.

You may also see this for a PHP built-in function. Try searching for the function in the official manual, and check what "extension" (PHP module) it belongs to, and what versions of PHP support it.

In case of a missing extension, install that extension and enable it in php.ini. Refer to the Installation Instructions in the PHP Manual for the extension your function appears in. You may also be able to enable or install the extension using your package manager (e.g. apt in Debian or Ubuntu, yum in Red Hat or CentOS), or a control panel in a shared hosting environment.

If the function was introduced in a newer version of PHP from what you are using, you may find links to alternative implementations in the manual or its comment section. If it has been removed from PHP, look for information about why, as it may no longer be necessary.

In case of missing includes, make sure to include the file declaring the function before calling the function.

In case of typos, fix the typo.

Related Questions:

  • https://.com/search?q=Fatal+error%3A+Call+to+undefined+function




php documentation comments