Page 1 of 1

Intellisense idea (again)

PostPosted: November 30th, 2012, 5:26 pm
by BladeMF
Hey,

I was thinking about intellisense. Right now, in our projects (a lot of files) we have a lot of collection classes, whose base class implements Iterator interface. If/when you do foreach loops to search for such interface and infer the item type, there will be one problem: I know for a fact that PHP punishes severly performance-wise for every function entry and more for every class method entry. So, if we want to take advantage of that feature, we would have to override all the members of the interface in every inheriting class, because it has different item type, which might kill us instantly.

I was wondering, maybe we can come up with some comment syntax in the inheriting classes, for example
/*
* @implements Iterator<COrder>
*/
or
/*
* @implements Iterator of COrder
*/

I know that .NET-wise overriding is the way to go, but adding an additional method call (even with empty body) for thousands of operations will add significant overhead (welcome to the PHP world).

Please, everyone, feel free to share your thoughts too.

So, Jakub, Miloslav?

Re: Intellisense idea (again)

PostPosted: December 2nd, 2012, 1:09 pm
by Jakub Misek
Additional PHPDoc tag would be the easiest way how to extend IDE functionality. Also it does not add additional code and overhead to your application.

For typing items of array, there is an unofficial standard of @var ItemType[]. (Which will be supported by our tools soon). This tells IDE how to treat foreach control variable and how to access items thru [] operator.

This could be used for Iterator derived classes too, so foreach and [] would work as expected. But it wouldn't work for Iterator::current().

Maybe we could add something like @var Iterator<ItemType> (it have to be single world, without spaces) over class declaration ...

Re: Intellisense idea (again)

PostPosted: December 4th, 2012, 9:00 am
by BladeMF
Jakub Misek wrote:Additional PHPDoc tag would be the easiest way how to extend IDE functionality. Also it does not add additional code and overhead to your application.

For typing items of array, there is an unofficial standard of @var ItemType[]. (Which will be supported by our tools soon). This tells IDE how to treat foreach control variable and how to access items thru [] operator.

This could be used for Iterator derived classes too, so foreach and [] would work as expected. But it wouldn't work for Iterator::current().

Maybe we could add something like @var Iterator<ItemType> (it have to be single world, without spaces) over class declaration ...



Agreed. Do you currently support @var inline? And, we should be able to declare a type with this attribute, for example:
/*
* @implements/class/?! Iterator<SomeSort>
* or
* @typeInfo SomeSort[]
*
*/
class ArrayOfSomeSort {
}

There should be a way to add more than one of those attributes (for each interface). What do you think?

Re: Intellisense idea (again)

PostPosted: December 4th, 2012, 4:20 pm
by Jakub Misek
I would rather to avoid defining new PHPDoc tag. For reference these are standard http://en.wikipedia.org/wiki/PHPDoc#Tags .

We can simply use @var over the class declaration. Or we can take a look on other IDE's, whether there is something already being used.

Re: Intellisense idea (again)

PostPosted: December 6th, 2012, 12:26 pm
by BladeMF
Jakub Misek wrote:I would rather to avoid defining new PHPDoc tag. For reference these are standard http://en.wikipedia.org/wiki/PHPDoc#Tags .

We can simply use @var over the class declaration. Or we can take a look on other IDE's, whether there is something already being used.



Yes. Maybe @var is not such a bad idea, since we are documenting the this[] property... Looking to other IDEs is a good idea - maybe Zend?

Re: Intellisense idea (again)

PostPosted: February 2nd, 2013, 2:39 pm
by Jakub Misek
bump

array intellisense ready for 1.6 release (in private beta already) -> PHPDoc supports following type names for class properties (@var), function parameters (@param), global variables (@global), function return type (@return) etc.

ClassName[] // simple array containing elements of type ClassName
ClassName[][] // and more [] ...
array // generic untyped array

I suggest to add support of @var also above class declaration? Which would override behaviour of instance of such class. For your Iterator classes, common array PHPDoc syntax would fit your needs I guess. E.g.
Code: Select all
/**
 * @var X[] This is Iterator and returns objects of type X.
 */
class A extends Iterator{}
Description of this @var element would appear as a variable tooltip.