Code complete failing between classes in separate files.
Hello,
Relatively straight forward setup, four .php files (see below for code, or attached):
country.php:
<?php
/** @noinspection PhpMissingDocCommentInspection */
class Country
{
/**
* @return string
*/
public function GetDisplayName()
{
return "My Country";
}
}
?>
main.php:
<?php
include('country.php');
include('order.php');
include('shipping.php');
?>
order.php:
<?php
/** @noinspection PhpMissingDocCommentInspection */
class Order
{
/**
* @return bool|Shipping
*/
public function GetShipping()
{
if(rand()===5)
{
return false;
}
else
{
return new Shipping();
}
}
public function Check()
{
$Shipping=$this->GetShipping();
if($Shipping!==false)
{
$Country=$Shipping->GetCountry();
if($Country!==false)
{
//Where's the code complete???
$Country->
}
}
}
}
?>
shipping.php:
<?php
/** @noinspection PhpMissingDocCommentInspection */
class Shipping
{
/**
* @return bool|Country
*/
public function GetCountry()
{
if(rand()===5)
{
return false;
}
else
{
return new Country();
}
}
}
?>
Within the order.php file I don't get any code completion for the Country object, however moving the Shipping class to order.php works fine... PHPStorm can find all the file and classes just fine so I've wasted the best part of a day figuring out what exactly is causing this and I'm guessing this is a bug but I'd like to be sure... Can't say I'm too impressed with this issue...
Thank you.
Attachment(s):
shipping.php.zip
order.php.zip
main.php.zip
country.php.zip
Please sign in to leave a comment.
Hi there,

1) What's you PhpStorm version?
Your example is working just fine here on PhpStorm 6.0.3 on Windows 7 x64;
2) If you place your code in brand new empty project -- will it behave the same?
3) Have you tried "File | Invalidate Caches..." ?
Hello Andriy,
Thank you - upgrading to the latest version seems to have fixed this issue.
Thanks.
Hi Andriy,
It seems this issue is a little more persistent and not too consistent, I encountered the same issue a couple of days after the original post and just gave up with PhpStorm, went and bought PhpEd which couldn't have been a bigger mistake so much so I've had to format. I'm back to trialling PhpStorm and would like to perservere with this issue to see if it can get sorted before purchasing it. I have uploaded a zip file of the project trimmed as much as possible to demonstrate the issue and have refactored class names etc. I'm running version 6.0.3. The issue occurs on line 45 of SCO.php:
30: $ADR=$this->GetADR();
...
45: $ADRCNTID =$ADR->GetCNT();
46: $ADRCNTID =$ADRCNTID->GetID();
Line 30 correctly assigns an ADR object to $ADR and line 45 is meant to assign the CNT object to $ADRCNTID, however it seems as though something is going wrong somewhere here as the CNT object gives no code completion prompts.
Thanks.
Attachment(s):
Problematic.zip
It's a bug in IDE for sure (at least this is how I see it).
If I rename your ADR class to ADDR or AADDR -- nothing changes. But if I rename it to CADR or MADR or MADDR -- it works fine.
At the same time -- without renaming anything: if you generate proper PHPDoc for SCO::GetADR() method, it will change nothing:
BUT .. if you remove "|bool" from @return ... it magically starts working.
It looks like class name that will ALPHABETICALLY go before "bool" (in this particular case) is causing the problem -- IDE looses the class completely.
I can only suggest you to do some more testing (with real class names) .. and if you get the same results -- create a Bug ticket at the Issue Tracker providing your example project (and link to this thread). Hopefully devs can narrow this issue fast and it will be available in v7 (no more v6 releases; v7 EAP program has already started)