NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code completion for objects assigned to variables


Joined: 05 Aug 2008
Posts: 7
Reply with quote
Currently in the IDE, when you assign an object to a new variable, the code completion for the new variable does not work. You cannot access the variables & methods represented in the object that was assigned to the variable.


$aPerson = $this->PersonDAO->getPersonById(5);
//this method returns an object of person

$aPerson->
//no code completion or intellisense is presented

instead, I am forced to temporarily add the following code in order to access variables/methods off of the new variable:

$aPerson = new Person (x,x,x,x);

Please enhance the IDE to be aware of objects being assigned to variables, and enable the code completion on those variables (now objects).

Love PhpED!
Chris
View user's profileFind all posts by cthorne66Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
instead, I am forced to temporarily add the following code in order to access variables/methods off of the new variable

No, you're not forced at all. Please read Type Hints topic.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 05 Aug 2008
Posts: 7
Reply with quote
Thanks for the information dmitri. So in my example, I had to place the following text directly above the function "getPersonById" that returned a Person.

/**
* @return Person
*/

However, it is still an extra step above all functions that return objects. It would be so nice for it to just know. Perhaps it's a limitation of PHP?
View user's profileFind all posts by cthorne66Send private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
However, it is still an extra step above all functions that return objects


not at all. If your function has something like below:

$a=new myobject();
return $a;

it will be recognized as returning myobject without any type hints.
Also it will be recognized if it returns class property of a known type and so on.
In other words, your function should be "clear" enough to be recognized. Otherwise, you'd add type hint.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 05 Aug 2008
Posts: 7
Reply with quote
Code is as you say, and is returning a clear object. The IDE doesn't recognize it as object.

In other words, with a fake example...

Working

$a = new Person(x,x,x,x);
$a-> //code completion works



Not Working

function getPerson(){
$person = new Person(x,x,x,x);
$person-> // code completion works here
return $person
}

$aPerson = $this->getPerson();
$aPerson-> //code completion doesn't work here without type hint

I would be more than happy to provide you with some screenshots if you would like to take this dicussion offline.

Thank you!
Chris


Last edited by cthorne66 on Wed Dec 10, 2008 11:14 pm; edited 1 time in total
View user's profileFind all posts by cthorne66Send private message


Joined: 05 Aug 2008
Posts: 7
Reply with quote
I should also mention that this issue is seen accros files. File A contains "function getPerson()" and file B is assigning the returned object to a variable.
View user's profileFind all posts by cthorne66Send private message
Code completion for objects assigned to variables
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic