Code Insight and Regsitry |
|
when defining $dbconn as a property of the object you're using, use PHPDoc comments to set the type.
eg. /** * @var $dbconn DBConn */ |
||||||||||||
|
Site Admin
|
if $registry->get() returns instance(s) of the same class, it's more appropriate to have @returns in the PHPDOC for this method, otherwise, you'll need to add typehints with all calls like suggested by Cjunge
|
||||||||||||
_________________ The PHP IDE team |
|
Cheers Cjunge, can't belive I didn't think of that.
Dmitri, not sure setting return will work because dependant on the string the registry returns at the moment three different objects. |
||||||||||||
|
|
Right...
Adding type hints for every instance of an object is tedious. Dmitri your solution doesnt work because ->Get() doesnt always return the same object, it depends on the string passed in. |
||||||||||||
|
Site Admin
|
Code Insight does never execute the code to see the results. Unfortunately you develop a code that can't be understood without executing (this is what people refer to as 'dynamic nature of php') therefore code insight can't recognize the classes without typehints. There are two possible ways: a) derive all possible returning classes from just one ancestor and move as much methods and properties to it (use "abstract" when appropriate). then define your Get in the typehint as returning this ancestor class b) if a) is not possible, you can apply typehints to the variables that you assign the value returned by Get()
That's why I recommended to apply typehints to properties and methods. |
||||||||||||||||
_________________ The PHP IDE team |
|
|
||||||||||||||||
|
Site Admin
|
do you mean your code or typehints? If you need examples on how to use typehints please check FAQ forum. If you have problems with typehints in your particular code fragment, please provide clear and short example. |
||||||||||||||
_________________ The PHP IDE team |
|
I did:
/** * @var $db NewADOConnection */ $db = $registry->get('DB'); Then later in the code if I start typing $db-> it does not bring up the code insight tooltip. |
||||||||||||
|
Site Admin
|
typehint shown below would be more correct:
Please note that @var always relates to the variable assigned below so it does not require the variable itself. Although you can add it, but after the class name. Regarding Code Insight Tooltip, it's not expected for the db->| position. You may get Code Insight popup with members of NewADOConnection class listed there. While Tooltip will be shown when you start entering method (or function) arguments. |
||||||||||||||
_________________ The PHP IDE team |
|
Still can't get it to work.... using
/** * @var Session */ $session = $registry->get('Session'); This doesnt give any code insight whatsoever. |
||||||||||||
|
|
Does it matter if we do not specifically include the session class file? This is also automatically included by the registry using a factory design pattern (another class).
I figured phped would auto load any files within the project. |
||||||||||||
|
Code Insight and Regsitry |
|
||
Content © NuSphere Corp., PHP IDE team
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by
Powered by phpBB © phpBB Group, Design by phpBBStyles.com | Styles Database.
Powered by