Force Zend Casting and Help the IDE Autocompletion

IDEs and Autocompletion

One of my favorite things in IDEs, in my case Eclipse for Mac, is that they offer you the option of autocompletion. No developer knows the entire set of functions of the language he uses, neither the set of parameters of them. That’s why IDEs come to help.

In many cases when casting is not obvious and method call chain is to large your IDE may refuse to help you with this brilliant functionality. To be more precise let me give you an example.

In Zend Framework I was trying to fetch a RSS via Gdata interface. Something like that:

$videoFeed = $gdata->getUserUploads('youtube_username');
foreach ($videoFeed as $entry) {
    // do something
}

The problem is that whenever I try to do $entry-> in the body of the foreach loop I don’t see what methods are supported by the Zend_Gdata_YouTube_VideoEntry class. So I tried to force the casting of $entry to this class definition and it worked like a charm for me. The thing I’ve done was to add a definition of $entry before the loop body:

$videoFeed = $gdata->getUserUploads('youtube_username');
$entry = new Zend_Gdata_YouTube_VideoEntry();
foreach  ($videoFeed as $entry) {
    // do something
}

Than whenever you try to type $entry-> you’d receive a list of methods from the class definition of Zend_Gdata_YouTube_VideoEntry.

Thanks to Roy Ganor there’s a more elegant way to do this, simply by adding @var comment:

/* @var $entry Zend_Gdata_YouTube_VideoEntry */

Related posts:

  1. Iterate over YouTube Channel with Zend_Gdata_YouTube
  2. Retrieving YouTube Channel’s Videos with Zend_Gdata_YouTube
  3. Check YouTube Video Existence with Zend_Gdata_YouTube
This entry was posted in micro tutorial, snippets, zend framework and tagged , , , . Bookmark the permalink.

8 Responses to Force Zend Casting and Help the IDE Autocompletion

  1. john says:

    finally. i was trying to make eclipse by some configs, but nothing worked at all. now that’s OK

  2. miso says:

    Yeah, me too.

  3. julio says:

    hi,

    actually this didn’t work with zend studio, which is eclipse. why’s that?

  4. Roy Ganor says:

    Hi,
    There is a nice way to provide type hinting in Eclipse/Zend Studio by providing a @var comment (provided by the PHP language as well).

    Read more content assist hints in this presentation: http://www.slideshare.net/royganor/zend-studio-tips-and-tricks

  5. Roy Ganor says:

    BTW, you can utilize it for your example by:
    http://bit.ly/cBx9sT

    enjoy ;)

  6. Stoimen says:

    @Roy Ganor – thanks so much, that was absolutely the solution I was missing. That’s really elegant!

  7. alandra says:

    nice

  8. rocio says:

    hi! eclipse the end

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">