[resolved] Code completion when object name is a variable |
|
|
||||||||||||
|
|
Can anyone at Nusphere confirm that this is a PhpED bug, or if I'm just doing something wrong? If it's a bug, will there be a fix?
|
||||||||||||
|
Veteran
|
Hi there- looked at it, sorry it took a bit. We can not always determine what would be assigned to the variable wheny you create it - this dynamic typing nature of PHP for you. But We di have FAQ on this subject, explaining how to deal with that:
http://forum.nusphere.com/tip-type-hints-t1563.html I hope it helps. BTW- thank you very much for answering other people's questions, it is always very much appreciated. |
||||||||||||
|
|
Thanks for the reply. No need to reply quickly with an answer. I just like to know that someone has seen it and will look into it at some point =)
Unfortunately it doesn't look like that link helps in my situation. I'm trying to use a string ("$objName") to define the name of the object that I was to use, but it looks like PhpED doesn't recognise that. I use this often in larger projects to define which object to load. I am unaware of the challenges associated with developing a code completion system, but would it be an option to make my code above work, possibly by checking to see if "$aVariable" is a string, and if it is, using the string value to reference an object or possibly even a function, like PHP does when it parses the code? E.g.
I realise that this could possibly be incredibly difficult to do, but it would be a major boon to code completion. Please feel free to give me technical details if you want to, as I would love to hear about the challenges involved with this. |
||||||||||||||
|
Site Admin
|
I think there is a kind of misunderstanding. What YFaktor pointed out to works pretty well: You may notice a phpdoc comment to tell the IDE what type will have the variable below. Typehints are explained there: http://forum.nusphere.com/tip-type-hints-t1563.html
no, php recognizes this during run-time, not while parsing. |
||||||||||||||||
_________________ The PHP IDE team |
|
I tried the phpdoc @var, but I obviously didn't do it correctly. Thanks for the clarification. It's working perfectly!
Thanks for the clarification. |
||||||||||||||||||||
|
|
Oops. It appears that I spoke too soon. The point of using a string (in your example, $objName) to specify the class name is that we don't know what class name will be used. Consider the following:
I don't know what to put for the phpdoc @var because I don't know which $objName will be used. Let me know if I'm missing something. |
||||||||||||||
|
Site Admin
|
If the classes have a common ancestor (or common interface), I'd recommend you to put it in the @var.
If the have no common ancestor, I'd say that code is not well designed and nobody would tell what methods are available, including phped's code insight |
||||||||||||
_________________ The PHP IDE team |
|
Ah, I was focussing too much on this example and not enough on my real-world code. I just needed to wrap my head around the whole process, and put my base inheritance class in the @var. Thanks for the help, dmitri. This is going to save me a ton of time =) |
||||||||||||||
|
[resolved] Code completion when object name is a variable |
|
||
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