Auto complete for dynamic methods

hi every body
in my project there is a part that generate dynamic functions and method that phpstorm can not detect them
are there any way to define that functions or class or methods that phpstorm can show it when typing code ?

it's not important how it is hard for example in a file i define that functions or method then phpstorm appear them in drop-down menu for auto complete

4 comments
Comment actions Permalink

Hi there,

Please show an example -- just to be 100% clear on what exactly you have there.

In any case:

  • dynamically-created function (normal function, not a class method) -- easy -- just create it in some .php file (stub file -- just a declaration (name, parameters, PHPDoc) -- leave body empty) and place such file anywhere in the project  -- it will be used for IDE only. That's actually how all known to PhpStorm functions/classes are done anyway.
  • dynamically-created class -- the same idea as above (as long as class name is unique)
  • dynamically-created methods -- it depends. Usually it's done via @method PHPDoc tag in the class where they are declared. But if you cannot edit that class (e.g. 3rd party library) then no -- you cannot "attach" aditional members to already defined class ( http://youtrack.jetbrains.com/issue/WI-851 ).
0
Comment actions Permalink

thanks for your answer
your solution worked for me
but what about this type of class:

class1.php :

class1{

     public function test(){
          echo "this is test";
     }
}


class2.php:

class2{

          public $myClass;      public function __construct(){           $this->myClass();      }      private function myClass(){           include_once 'class1.php';           $this->myClass=new class1();      }
}


index.php:

include_once 'class2.php';
$test=new class2;
$test->myClass->test();



suppose all of above codes are dynamic for example i have the function like this:

function myFunc(){
     include_once 'class2.php';
     return new class2;
}


and i access to this function everywhere so my codes works like this:

myFunc()->myClass->test();


i expected when i type myFunc()-> ... it shows me myClass and when enter and again put -> then it shows me test();  but it didn't work
i create an unusable php file called auto.php and put this codes there as you said before:

function myFunc(){

     class myFunc(){


     }

     return new myFunc;

}


then myFunc() appears in auto complete list but it only shows myClass means myFunc()->myClass  but it doesn't show test() when i put a -> after it myFunc()->myClass-> (nothing)

that was interesting while i open this project in eclipse and it worked there means auto complete list for myFunc()->myClass->test() (but didn't work in phpStorm)

see screenshots in real project (that it worked in eclipse):
1.this is my class:
Selection_150.jpg
2.this the function that i have access to it everywhere and i load my class inside it:
Selection_149.jpg

3. this is what i put in auto.php for generate auto complete list:
Selection_152.jpg
4. the result that i got in eclipse (see picture if doesn't show below http://axgig.com/images/06415002578666151469.png ):
Screenshot from 2013-07-05 18:29:31.png
5. and doesn't get same result in phpStorm (see http://axgig.com/images/33047926276403682707.png ):
Screenshot from 2013-07-05 18:39:30.png

0
Comment actions Permalink

Sorry .. I'm still not 100% clear on the actual issue (I mean -- what files you can edit and what not).

But regarding your example -- this solves it:

class class2
{     /** @var class1 */     public $myClass;
0
Comment actions Permalink

thanks a million it worked

0

Please sign in to leave a comment.