Skip to main content



      Home
Home » Language IDEs » PHP Development Tools (PDT) » wrong Design or Problem of PHP resp. PDT
wrong Design or Problem of PHP resp. PDT [message #560092] Tue, 21 September 2010 03:52 Go to next message
Eclipse UserFriend
hi,

i have a question about auto-complete methods from return Objects.

to explain a little code.


class node {
	public $age = 10;
	
	public function __construct(/*int*/ $age){
		$this->age = $this->age + $age;
	}
	
	public function getAge(){
		return $this->age;
	} 
}

class tree {
	
	public static function getNodes(/*int*/ $number){
		$nodes = array();
		for($i=0; $i<=$number; $i++){
			$nodes[] = new node($i);
		}
		return $nodes;
	}
}

$Tree = tree::getNodes(9);
foreach($Tree as $Node){
	echo 'Node age:'.$Node->getAge();
}	




the auto-complete function does not work on the
$Node in the last for-each loop.

I think, it is because PDT don't know the elements in the Array.
If i return the object directly (also only one) the auto-complete function works correctly.

In Java there are Return Types and and everything is a Object.
There are no Problems with this.

Is the code above only a design error?

Is there a other method to code something like this?










Re: wrong Design or Problem of PHP resp. PDT [message #626140 is a reply to message #560092] Wed, 22 September 2010 08:24 Go to previous messageGo to next message
Eclipse UserFriend
Add type comment.

$Tree = tree::getNodes(9);
foreach($Tree as $Node){
	/* @var $Node node */
	echo 'Node age:'.$Node->getAge();
}


see also
Bug 170968 - Use PHPDoc hints for arrays of objects
Re: wrong Design or Problem of PHP resp. PDT [message #626262 is a reply to message #626140] Wed, 22 September 2010 09:14 Go to previous messageGo to next message
Eclipse UserFriend
thank you,

this helps me a lot.
i have not found this answer somewhere.

Also it is a problem of PHP, because PHP dont understand return types.

in this case i should make this comment in all
loops.

adv. better:


class tree{
  public /* @return array node */ function getNodes(){
  ... return array... 
  }
}



or something like this.
perhaps in future versions of PHP.
Re: wrong Design or Problem of PHP resp. PDT [message #629015 is a reply to message #626262] Sat, 25 September 2010 22:06 Go to previous message
Eclipse UserFriend
I've made a small helper plugin for Content Assist against object variable in 'foreach' block.
It makes possible to CA in some cases, ...
It works on PDT 2.2.1 (Helios SR1) and in 'foreach' block only.

http://sourceforge.jp/projects/pdt-tools/releases/49081/
(sorry, no release note in English)
Previous Topic:Incorrectly formatting source code
Next Topic:Displaying defines?
Goto Forum:
  


Current Time: Wed Jul 23 02:08:49 EDT 2025

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

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

Back to the top