Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » phpDoc @property tag not working.
phpDoc @property tag not working. [message #73646] Tue, 17 June 2008 14:23 Go to next message
Eclipse UserFriend
Originally posted by: runar.b.olsen.gmail.com

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?

Example:

<?php

/**
* @property Foo $foo
*/
class Registry {
private $datastore = array();

public function __get($var) {
if(array_key_exists($var, $this->datastore) {
return $this->datastore[$var];
}
return false;
}
}

class Foo {
public function bar()
{
echo 'FooBar!';
}
}

$reg = new Registry();

// There is no foo in the auto complete list here
$foo = $reg->foo;
// Typing in $foo-> does not tell me about the bar method.
Re: phpDoc @property tag not working. [message #73664 is a reply to message #73646] Tue, 17 June 2008 16:20 Go to previous messageGo to next message
Roy Ganor is currently offline Roy GanorFriend
Messages: 149
Registered: July 2009
Senior Member
Hi Runar,

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?

> Example:

> <?php

> /**
> * @property Foo $foo
> */
> class Registry {
> private $datastore = array();

> public function __get($var) {
> if(array_key_exists($var, $this->datastore) {
> return $this->datastore[$var];
> }
> return false;
> }
> }

> class Foo {
> public function bar()
> {
> echo 'FooBar!';
> }
> }

> $reg = new Registry();

> // There is no foo in the auto complete list here
> $foo = $reg->foo;
> // Typing in $foo-> does not tell me about the bar method.
Re: phpDoc @property tag not working. [message #991316 is a reply to message #73646] Tue, 18 December 2012 14:12 Go to previous message
Mateusz P is currently offline Mateusz PFriend
Messages: 1
Registered: December 2012
Junior Member
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();
		}
	}
}
Previous Topic:Debug Display view functionality
Next Topic:eclipse pdt editor not showing error
Goto Forum:
  


Current Time: Thu Apr 25 22:34:45 GMT 2024

Powered by FUDForum. Page generated in 0.03053 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top