New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looping through public property of array of objects fails to auto complete #142

Closed
dbone opened this Issue Apr 8, 2015 · 2 comments

Comments

Projects
None yet
5 participants
@dbone

dbone commented Apr 8, 2015

PHP auto-completion inside a foreach loop of an array of objects stored in a parent object property fails.

class SubTest {
  public $name = null;
}
class Test {
  public $testName = null;
  /** @var SubTest[] */
  public $subTests = null;
}
$test = new Test();
// (do some setup here)
foreach($test->subTests as $subTest) {
  $subTest->...

At the ellipses you get "could not resolve first part of 'subTest'" or retrieves the auto-complete info for the parent class Test. But using the same class if you do the following:

$subTests = $test->subTests;
$subTest0 = $subTests[0];
$subTest0->...

Here the ellipses auto-complete the properties correctly.

Thanks,
-d

@cgchoffman cgchoffman added this to the 9.1 milestone Apr 10, 2015

@Naatan Naatan modified the milestones: 9.1, 9.1.1 May 19, 2015

@Naatan Naatan modified the milestones: 9.1.1, 9.2, 9.3 Jun 23, 2015

@thnt

This comment has been minimized.

thnt commented Feb 18, 2016

For above example, this works fine:

foreach($test->subTests as $subTest) {
   $subTest->...
}

but this not:

$subTests = $test->subTests;
foreach($subTests as $subTest) {
   $subTest->...
}

this not, too:

class SubTest {
  public $name = null;
}
class Test {
  public $testName = null;
  /** @var SubTest[] */
  public $subTests = null;

/** @return SubTest[] */
  function getSubTests() {
     return $this->subTests; 
 }
}
$test = new Test();
// (do some setup here)
foreach($test->getSubTests() as $subTest) {
  $subTest->...
}
@mitchell-as

This comment has been minimized.

Member

mitchell-as commented Feb 18, 2016

Thanks for the report. I'm not sure if our codeintel supports return types like that in your last example though.

@mitchell-as mitchell-as reopened this Feb 18, 2016

@mitchell-as mitchell-as modified the milestones: 9.3.3, 9.3 Feb 18, 2016

mitchell-as added a commit that referenced this issue Feb 22, 2016

fix: codeintel: Fixed more instances of PHP completion with `foreach` -
fixes #142

rn=

(integrated from 9.3.x branch change 9.2.1-747-gfd4b5dc by Mitchell <mitchellb@activestate.com>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment