Community
Participate
Working Groups
Build ID: I20080617-2000 Steps To Reproduce: Create this file: <?php class Foobar { public function nonsense() { } } $className = 'Foobar'; $obj = null; /* @var $obj ReflectionClass */ $obj-> // (no code completion) More information: This works in Eclipse 3.3.2 with PDT 1.0.3, but not in Eclipse 3.4 with PDT 1.1.0.20080616. What happened to the comments that can "help" the autocompletion?
Sorry, I copied and pasted my proof-of-concept. This might make more sense: <?php class Foobar { public function nonsense() { } } $obj = null; /* @var $obj Foobar */ $obj-> // (no code completion)
(In reply to comment #1) > Sorry, I copied and pasted my proof-of-concept. This might make more sense: > <?php > class Foobar > { > public function nonsense() > { > } > } > $obj = null; > /* @var $obj Foobar */ > $obj-> > // (no code completion) hi, have you tried to put the comment before the assignment? <?php class Foobar { public function nonsense() { } } /* @var $obj Foobar */ $obj = null; $obj-> // (code completion should be here)
reply to comment #2) > have you tried to put the comment before the assignment? Hi, Roy. Putting the hint before the assignment doesn't work either. Besides, there are times when you don't know the type to hint until after the variable has been assigned; example: function( $foo ) { if ( $foo instanceof ReflectionClass ) { /* @var $foo ReflectionClass */ // $foo-> } else if ( is_string($foo) ) { // etc... } } Furthermore, putting the hint after the assignment worked in 1.0.3 ;) Thx, ―DC
Yeah, doesn't work for me either. Code completion is very flakey in 1.1 Sometimes it finds stuff, but most of the time, it just says "No completions available". And "Open Declaration" doesn't work either, so I can't use that to jump to the appropriate files/positions in the file.
Well, it randomally works for me :), indeed we should fix this problem (In reply to comment #4) > Yeah, doesn't work for me either. > Code completion is very flakey in 1.1 > Sometimes it finds stuff, but most of the time, it just says "No completions > available". And "Open Declaration" doesn't work either, so I can't use that to > jump to the appropriate files/positions in the file.
This feature works like follows now: 1. /* @var ... */ must precede to variable declaration (which is an assignment) For example, in your case the following structure will work: /* @var $foo ReflectionClass */ $foo = $foo; $foo-> I agree that this is a workaround rather than a solution. 2. Normally, variable type should be detected by type inferencing engine using various hints, like: a. Function argument type hint: function foo(A $var) { ...} b. Function return type: $var = foo(); // foo is declared as returning "A" in PHPdoc, or there's a 'return' statement, which can be evaluated. c. Explicit declaration: $var = new A(); d. etc... (In reply to comment #3) > reply to comment #2) > > have you tried to put the comment before the assignment? > > Hi, Roy. > Putting the hint before the assignment doesn't work either. > > Besides, there are times when you don't know the type to hint until after the > variable has been assigned; example: > > function( $foo ) { > if ( $foo instanceof ReflectionClass ) { > /* @var $foo ReflectionClass */ > // $foo-> > } else if ( is_string($foo) ) { > // etc... > } > } > > Furthermore, putting the hint after the assignment worked in 1.0.3 ;) > > Thx, > ―DC >
*** Bug 249705 has been marked as a duplicate of this bug. ***
the explanation Michael provided is fine by me. If there is a specific example were the type inferencer does not work as expected a new issue should be submitted.
Verified on N20081022 Closing [Sylvia Tancheva]
Please consider to reopen this bug (I'm not allowed to do so myself): (In reply to comment #6) > 1. /* @var ... */ must precede to variable declaration (which is an assignment) > For example, in your case the following structure will work: > > /* @var $foo ReflectionClass */ > $foo = $foo; > $foo-> > > I agree that this is a workaround rather than a solution. Definitely. And you probably won't expect anybody to use such a nonsensical line of code in any kind of production-level software, since this line won't survive a review / refactoring (carried out by someone who is not familiar with this specific bug). Another example: <?php class Foo { public $bar; /** * @return array */ public static function getArray() { // ... } } foreach (Foo::getArray() as $anElement) { /* @var $anElement Foo */ $anElement->| // invoke code-assist here } ?> Another (probably even better) option would be to improve the phpdoc-parser/type-inference-engine to handle stuff like "@return array[Foo]" (or whatever the appropriate syntax is in this case). I think Bug 170968 already covers this RFE. In the meantime, the explicit type-hinting should be fixed (without resorting to kludges like "$foo = $foo").
Dear Great PDT Developers, This bug does not appear to be fixed in the latest stable release of PDT 2.0. I have confirmed this problem on two different workstations, one running OS X, and the other Windows XP. This bug is driving our development staff up the wall. We need our type hints! :-) Best, Nick
Created attachment 123402 [details] Bugfix The patch fixes the problem of null re-assignment.
Created attachment 123670 [details] patch and unitest for the issue 1. Fix to the problem described. 2. Unitest for the problematic behavior.
Created attachment 123673 [details] golden for the test Golden file for the test provided in a previous attachment
Created attachment 123675 [details] fix for canse insesitive typing fixed in trunk
Contributed by Vadim P. Unit test: CODE: <?php class Foobar { public function nonsense(){} } /* @var $obj Foobar */ $obj = null; $obj->| ?> COMPLETIONS: [METHOD_DECLARATION]{completion:nonsense(), declSign:, declKey:, key:, name:nonsense, [106,106], relevance=1000000}
*** Bug 260330 has been marked as a duplicate of this bug. ***
I'm sure it worked without assignment prior to 2.0, ie I remember using it. Problem with this only-assignment policy is that its useless with foreach, ie if you have an array of objects. Perhaps it can be reverted to old way, ie just apply type hint to closest var with that name? (In reply to comment #6) > This feature works like follows now: > > 1. /* @var ... */ must precede to variable declaration (which is an assignment) > For example, in your case the following structure will work: > > /* @var $foo ReflectionClass */ > $foo = $foo; > $foo-> > > I agree that this is a workaround rather than a solution.