Wednesday, March 16, 2011

Can you hint return types in PHP 5.2.5?

I think my eclipse's ctrl+clicking links might benefit greatly...

Edit: I'm using eclipse PDT.

Edit 2: I'm very happy with the solution of putting docblocks before functions (and variables) with an @return or @var statement, I've just updated the documentation of my app and now eclipse is showing me what functions are available to what objects!

Awesome.

From stackoverflow
  • Short answer: no.

    Long answer: consider adding docblocks with @returns declarations.

    Dean : Nope, docblock didn't help.
    azkotoki : It works for me. What eclipse plugin are you using for php development?
    troelskn : It's @return -- not @returns
    Dean : Strange, after some time it did work. But I didn't see a "building" status bar at the bottom or anything like that. Thanks!
  • // [...]
    /**
     * Return the Request object
     *
     * @return Zend_Controller_Request_Abstract
     */
    public function getRequest()
    {
        return $this->_request;
    }
    // [...]
    

    works perfectly with Eclipse PDT. Which plugin do you use?

    MrSnowflake : How do you define the type of objects inside a returned array?
    Stefan Gehrig : I don't think that's possible with current Eclipse PDT or Netbeans.
    Stefan Gehrig : As far as I know at least the PDT team is looking at this issue.
  • The only way to hint return type in PHP is to use a good IDE like Eclispe PDT or Zend Studio with standard comment block. PHP simply can n not predict return type because it is dynamically typed language so type checking is done in the run time unlike for the statically typed languages like C#, JAVA and C++.

0 comments:

Post a Comment