This Question is Answered

2 "helpful" answers available (2 pts)
2 Replies Last post: Jun 25, 2013 7:59 PM by Quazi  
Quazi Newbie 5 posts since
Jun 25, 2013
Currently Being Moderated

Jun 25, 2013 4:41 PM

Code complete not working on class functions.



I've just downloaded the demo of PhpStorm afteran incredibly frustrating couple of hours with phpDesigner. I've code some very basic code, and what is concerning is that PhpStorm does not appear to be performing any code complete on it - is this a limitation of a demo?


File 1:


    class TestClass{
        public function GetNumber(){
            return 55;
        public static function GetTestClasses(){
            return array(new TestClass(), new TestClass(), new TestClass());



File 2:






The code executes just fine, however in File 2, after typing $Current-> I could expect GetNumber to appear, yet it doesn't. As I say I'm only running the demo and I'm unsure if this is a limitation, however I would fully expect PhpStorm to be able to evaluate this. The two files are in different directories, although PhpStorm can find the TestClass from File 2 as I can hold CTRL and click 'TestClass' and it will jump right to it.



Andriy Bazanov Master 5,108 posts since
May 28, 2010
Currently Being Moderated
Jun 25, 2013 7:36 PM in response to: Quazi
Re: Code complete not working on class functions.

Hi there,


The "demo" version has no limitations -- it's fully functional version that has 30-days trial license. That's it.


The "problem" is in your code. To be specifically -- complete lack of documentation (type hints specifically). Adding 3 lines (or single line in compact form) of PHPDoc solved the problem for your example:

class TestClass
     * @return TestClass[]
    public static function GetTestClasses()
        return array (new TestClass(), new TestClass(), new TestClass());

    public function GetNumber()
        return 55;




Thing is: PhpStorm is not soooo advanced right now and does not see the difference between return array() and return array(someClass, someClass). -- the return type in both of such cases is just an array.


What I did is told IDE that return type is array of TestClass.


Alternative solution (when class cannot be altered, e.g. 3rd party library/framework) is to add similar kind of comment in place of usage:


$TestClasses = TestClass::GetTestClasses();
for ($Index = 0; $Index < count($TestClasses); $Index++)
    /** @var TestClass $Current */
    $Current = $TestClasses[$Index];

More Like This

  • Retrieving data ...