Lets say you have a class that acts as a registry and that contains the
magic methods __get($var) and __set($var, $value); Now for most of the
time you cannot be sure what type of variable __get will return but you
do know that __get('foo'); always will return a instance of the Foo
class. According to phpDoc (http://preview.tinyurl.com/2fxl57) you can
add the @property doc tag for the class defining that the property $foo
of the class Registery is a instance of Foo, but PDT does not seem to
take this into account when it comes to auto completing. Is this
something that will be included in a later release?
It's funny that you raise this issue today, because I have committed the
fixes this morning. for more details see this Bugzilla issue (Bug #235108
- [GoalEvaluator] Evaluate __call() __ get() functions and variables) https://bugs.eclipse.org/bugs/show_bug.cgi?id=235108
Eclipse PDT now supports both @property and @method tags that indicate
magic fields and methods.
I will appreciate it if you can check next nightly build and see if this
answers your requirements.
Regards,
Runar B. Olsen wrote:
> Hi,
> Lets say you have a class that acts as a registry and that contains the
> magic methods __get($var) and __set($var, $value); Now for most of the
> time you cannot be sure what type of variable __get will return but you
> do know that __get('foo'); always will return a instance of the Foo
> class. According to phpDoc (http://preview.tinyurl.com/2fxl57) you can
> add the @property doc tag for the class defining that the property $foo
> of the class Registery is a instance of Foo, but PDT does not seem to
> take this into account when it comes to auto completing. Is this
> something that will be included in a later release?
Hello, I would like to return to this subject. I've found a problem in my example with scenerio 3. It seems that the engine dosen't recognize the array symbol [] when used in @method tag. The popup hint show Foo[] correctly as return value but the autocomplete dosen't work.
<?php
/**
*
* @method Foo getOne() getOne()
* @method Foo[] getAllWithProblem() getAllWithProblem()
*/
class Foo
{
public function autocompleteWorks()
{
}
/**
*
* @return Foo[]
*/
public function getAllOkay()
{
return array( new Foo() );
}
static public function testScenerios()
{
// scenerio 1
$oFoo1 = $this->getOne();
// works
$oFoo1->autocompleteWorks();
// scenerio 2
foreach($this->getAllOkay() as $oFoo2)
{
// works
$oFoo2->autocompleteWorks();
}
// scenerio 3
foreach($this->getAllWithProblem() as $oFoo3)
{
// dosen't work
$oFoo3->
// scenerio 3 fix, but with nested classes dosen't work
/* @var $oFoo3 Foo */
$oFoo3->autocompleteWorks();
}
}
}