@var and public property

symfony2 has such code inside:

class Response {
    /**      * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag      */     public $headers;



When I access this property like:

$response->headers->setCookie(...);



PhpStorn do have auto-complete, but marks function as "not found in class".

Attachment(s):
20120409-bv76-17kb[1].jpg
1 comment
Comment actions Permalink

Try:

    /**
     * @var $headers \Symfony\Component\HttpFoundation\ResponseHeaderBag
     */
    public $headers;



In the case where your stuck with someone else's code, try
/* @var $headers \Symfony\Component\HttpFoundation\ResponseHeaderBag */
$headers = $response->headers;
$headers->setCookie(...);

A bit of a pain but well worth the extra line of code in order to get type aheads.  You might even be able to do:

/* @var $response->headers \Symfony\Component\HttpFoundation\ResponseHeaderBag */
$response->headers->setCookie(...);


Personally, I try to use the following rule:
If I am setting data, I always create a local variable in my method and use a comment to define it if neccessary.

If I am reading data only, I try to use the original object.


0

Please sign in to leave a comment.