Search code examples
phpnetbeansphpdoc

How to specify the IDE Netbeans, that the PHP variable has a specific type?


I have file with some PHP code, like this:

    <?php
        foreach ($ideas as $key => $idea) {
            $idea->getIdeaId();
            ?>

            <tr>
                <td>

                </td>
                <td>

                </td>
            </tr>

            <?php
        }
        ?>

Variable $ideas is an array of objects with type KIdea. How can I tell to Netbeans, what $idea in foreach will have type KIdea?

It's need for the code completition.

I have try something like

        <?php
        /**
         *  @param KIdea $ideas Description
         */
        foreach ($ideas as $key => $idea) {

and something like

        <?php
        foreach ($ideas as $key => $idea) {
            /**
             *  @var KIdea Description
             */
            $idea;
            $idea->getIdeaId();

but it's not helpful for the code completion.


Solution

  • With netbeans, you may document your variable with the following syntax :

    /* @var $variable MyClass */
    $variable = getSomething();
    
    // netbeans will assume that your variable is the MyClass type and will provide code completion.
    

    To auto-complete this string, you may use the following shortcut: type vdoc and press Tab key.

    Source for this answer on the Oracles's netbeans php blog.