This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 174991

Summary: [Type] code completion + vdoc + array acces
Product: php Reporter: honzamarek <honzamarek>
Component: EditorAssignee: Ondrej Brejla <obrejla>
Status: NEW ---    
Severity: blocker CC: tmysik
Priority: P3    
Version: 7.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Attachments: example

Description honzamarek 2009-10-20 12:39:39 UTC
I have a problem with code completion (ctrl + space).

$object = new Something; // class Something implements ArrayAccess

/** @var $var DirectoryIterator */
$var = $object["directoryIterator"];

$var->                   // it still offers methods and members for class Something not DirectoryIterator
Comment 1 Tomas Mysik 2009-10-20 14:07:58 UTC
Reassigning to the proper component, but anyway, closing as INVALID.

The correct form for vdoc template is just one "*" in the beginning (it's not PhpDoc, it's NetBeans' own extension)
so the correct code for your example is:

/* @var $var DirectoryIterator */

BTW do you know that you can type "vdoc" followed by TAB above $var = ... line and the template is generated for
you? BTW in the generated comment, code completion works for the type/class as expected.

I just verified that it works in the current dev build.

Thanks for reporting.
Comment 2 honzamarek 2009-10-21 14:20:35 UTC
Are you sure? In Netbeans Dev 200910170201 it still doesn't work.

I know that template. I wrote two stars because I assumed that there are two stars (I didn't copied it by ctrl c, ctrl v).
Comment 3 Tomas Mysik 2009-10-21 14:42:36 UTC
> Are you sure? In Netbeans Dev 200910170201 it still doesn't work.

Yes, still works for me. Feel free to attach a page where it does not.

I will attach my working example.

Product Version: NetBeans IDE Dev (Build 091021)
Java: 1.6.0_16; Java HotSpot(TM) 64-Bit Server VM 14.2-b01
System: Linux version 2.6.28-15-generic running on amd64; UTF-8; cs_CZ (nb)
Comment 4 Tomas Mysik 2009-10-21 14:46:52 UTC
Created attachment 89869 [details]
Comment 5 honzamarek 2009-10-21 15:39:31 UTC
Created attachment 89874 [details]
Comment 6 honzamarek 2009-10-21 15:45:29 UTC
Created attachment 89875 [details]
Comment 7 honzamarek 2009-10-21 15:51:25 UTC
It was more difficult to create non-working example than I originally thought. In most cases this problem doesn't exist.
Comment 8 Tomas Mysik 2009-10-21 16:08:49 UTC
OK, I see now. Please attach a sample project, we really need it to solve it because this feature mostly works.
Comment 9 Tomas Mysik 2009-10-21 16:09:49 UTC
Reassigning to Radek, please have a look at it (the last screenshot).

Marking as INCOMPLETE till the sample project is attached.

Comment 10 Tomas Mysik 2009-10-21 16:11:07 UTC
Sorry, I overlooked the example file. That should be enough.
Comment 11 rmatous 2009-10-22 12:29:26 UTC
Yes, this is obviously bug: dog can't be cat and vice versa. This issue has deeper roots(meaning that type inference for
arrays and array access is rather poor - we are aware of it but on the other hand its uneasy task that will take much
time - so, no special improvements can't be expected in near future - definitely not for 6.8)  

For your case:
        /* @var $dog Dog */
        $dog = $a["dog"]; 

Workaround exists:
        $dog = $a["dog"]; 
        /* @var $dog Dog */

Comment 12 Filip Zamboj 2010-09-15 12:30:21 UTC
batch reassigning
Comment 13 Petr Pisl 2011-06-08 12:23:23 UTC
Still valid. Arrays should be support more.
Comment 14 Ondrej Brejla 2012-04-12 09:19:04 UTC
It's a corner case and workaround exists, as Radek wrote. You can use varDoc under the $dog = $this[...] assignment. And as it's not supported right now (and never been), it's an enhancement for me.
Comment 15 sidtj 2012-10-14 04:12:18 UTC
Not even the proposed workaround is working for me.


    public function possuiUmaOuMaisParcelasPagas($contarEntrada = true)
        $entrada = $this->getRelated('parcelaEntrada');
        /* @var $entrada ParcelaCobranca */
        $entrada->[should show ParcelaCobranca methods but nothing happens]

Obviously I also tried to put vardoc over the assignment.

It should be a BUG not enhancement since it works in some places but does not in others.