Code Insite with methods having mixed return values |
Site Admin
|
Hi Mark,
I know, it's possible to write an even more sophisticated thing in such dynamic languages like PHP but to get the IDE a right IDEa about what types are where, you'd start using inheritance and types which means "more constraints" or use more phpdoc comments. With first approach (inheritance) I'd recommend you to define an ancestor class that will hold all common properties and methods that xxx_item classes have. In this case your code might look like this:
the key change is public function addItem($item) to public function addItem(an_item $item) alternatively you might have:
but it's closer to the 2nd approach, where phpdoc comments are used:
|
||||||||||||||||||
|
|
ddmitre,
Thanks for the quick reply. I tried both methods and both have a few drawbacks. The first method works but only methods and properties in the parent class of 'an_item' are discovered. Any methods and properties in 'foo_item' and 'bar_item' are not discovered by phpED. This however is what I would expect based on the current behavior of phpED. The second method also works however it requires one to add the special phpDoc tag to the code when the code self documents. The drawback is if you forget to add the phpDoc you don’t get any code insite for that object. I guess a third method would be to not pass objects to functions and/or methods by using the new keyword but rather create the instance of the object and assign it to a variable and then pass it along. For example.
I wonder if it could be possible for phpED to recognize this style of programming though. On the surface it seems reasonable. If a method or function is passed a parameter using the new keyword and returns that same parameter back then the return type should be considered the same type. Essentially, increase the scope in which phpED interprets the following code snippit.
Anyway, thanks for the reply. I’ll use the phpDoc method for now unless another solution comes along. |
||||||||||||||||
_________________ - Mark |
Code Insite with methods having mixed return values |
|
||
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