NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Code completion and array of objects


Joined: 15 Aug 2006
Posts: 21
Reply with quote
Is there any way how can I write hint for code completioner that variable is array of some type of objects?

Example (montage showing what I mean):

View user's profileFind all posts by dgxSend private messageVisit poster's website


Joined: 21 Nov 2009
Posts: 20
Reply with quote
+ 1

Similar feature request is already here: http://forum.nusphere.com/type-hinting-for-arrays-t5837.html

The problem is that there is no official syntax. Blizz thinks that the correct syntax is @var array(int => Component), but according to PHPLint (http://www.icosaedro.it/phplint/phpdoc.html#types) is the corrent syntax @var array[int]Component (this should be already supported by phpDocumentor).


Last edited by Jan Tvrdík on Mon Feb 01, 2010 11:14 am; edited 1 time in total
View user's profileFind all posts by Jan TvrdíkSend private message


Joined: 23 Jun 2008
Posts: 32
Reply with quote
+1

I'm totally for this!
View user's profileFind all posts by AirspraySend private message


Joined: 14 Aug 2009
Posts: 35
Reply with quote
+1

yes please.
View user's profileFind all posts by cr0wn3rSend private message


Joined: 27 Feb 2011
Posts: 8
Reply with quote
+1
View user's profileFind all posts by hrachczSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
this feature is supported by v7:

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


Joined: 27 Feb 2011
Posts: 8
Reply with quote
@dmitri: seems awesome, but does not work foreach cycle.
View user's profileFind all posts by hrachczSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
will work in the next build (7020)

btw, did you know that iteractors (with known class returned by current()) are supported in foreach?

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


Joined: 27 Feb 2011
Posts: 8
Reply with quote
Wow, it's awesome.
Btw, there is little bug:
Code:

class Obj() {
public function getObj();
}
function test() { return [new Obj();] }

test()[]-> // triggers help, but should not, sice ()[] is invalid.
View user's profileFind all posts by hrachczSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
If you mean that it's not/should not be possible to read from [], that's checked in RUN-TIME.
Such errors are hard to capture at COMPILE-TIME.
The following code is perfectly-valid and works as expected.

Code:

<?php

class Obj {
    public function getObj() {}
}

function test() {
    return [new Obj()];
}

test()[0]->|                 // <- shows getObj() method and after added, will show call-tooltip for this method
?>

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


Joined: 27 Feb 2011
Posts: 8
Reply with quote
Yes, you are right, I meant the missing index. However, it's better to suggest more than less Smile Thanks for explanation.
View user's profileFind all posts by hrachczSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
It's because php grammar works this way.
It first gets test()[] tokens grouped and at this time it could raise an error telling that [] is not properly used, but it can't because it does not know how this group will be used -- f/e test()[] = 5; (WRITE access) whic is okay -- you return a reference to an array from the function then add new element to it, and in the other case it can't be correct when you try to call something test()[]->method() (READ access) assuming that the function returned array of object instances. To distinct these two cases (Read and Write access to the array), it's necessary either detect the problem at run-time (which is what was done in php), or add new set of rules to the grammar and does not allow [] to appear in LVAL, but it's not that trivial to do.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Code completion and array of objects
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