NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Type hinting for arrays


Joined: 16 Dec 2008
Posts: 5
Reply with quote
Hi there

I've looked around on this forum and google for a way to do type hinting with arrays but can't find any examples.

I have an array in class A which is an array of class B objects:

Code:

class A
{
   $myArray = array();
}

class B
{
}


I could like to do type hinting so that if I do....

Code:

$a->myArray[0]->


...I get good code insight. My own thoughts would be something like:


Code:

class A
{
   /**
   * @var Array[ B ]
   */
   $myArray = array();
}


But that doesn't work. Does anyone know if it can be done?

Andrew
View user's profileFind all posts by acuthbertSend private message
Guru master

Joined: 05 Jul 2004
Posts: 659
Location: Belgium
Reply with quote
I think the correct format is @var array([<keytype>=>]<valuetype>) but I doubt PhpED has support for this. In any case, I never tried it.
View user's profileFind all posts by BlizzSend private messageVisit poster's website


Joined: 16 Dec 2008
Posts: 5
Reply with quote
Thanks Blizz,

I tried that but it didn't work unfortunately.

PhpED team - can we make this a feature request?

Andrew
View user's profileFind all posts by acuthbertSend private message


Joined: 31 Jul 2008
Posts: 17
Location: Basingstoke, UK
Reply with quote
Would be nice if we could get this included with PhpED.

Although we can still do things like this as a decent enough workaround if we have an array of objects:
Code:
foreach ($foo as /** @var DateTime */ $bar) {


Much better than the alternative hack that I had to use in Zend Studio:
Code:
foreach ($foo as $bar) { if (0) $bar = new DateTime();
View user's profileFind all posts by Lord d'EathSend private message


Joined: 09 Jul 2009
Posts: 13
Reply with quote
Did the first option not work for you in Zend Studio? I have a Zend Studio version that I use every now and again, but it was the last version before the release Zend Studio for Eclipse, so it's a little different.
View user's profileFind all posts by killermonkSend private message
Veteran

Joined: 30 Aug 2006
Posts: 116
Reply with quote
This would be a very very handy feature
View user's profileFind all posts by rudderSend private message


Joined: 21 Nov 2009
Posts: 20
Reply with quote
+1
View user's profileFind all posts by Jan TvrdíkSend private message
Type hinting for arrays
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