Let's say I create an object in index.php and save the reference in the variable $obj.
Later in index.php I include/require a file req.php where I want to use a method of the object.
Is there a way to make Aptana 3.0.4 show me the available methods of the object when I type $obj-> inside req.php?
I.e. Aptana should recognize that the variable $obj is already defined higher in the file hierarchy and that it holds a reference to an object.
May be it helps if you add comment before the first var using
/* #var YOUR_CLASS */
The correct syntax in version 3.0.4 is like that:
/**
* #var Foobar
*/
$obj; // You have to call the variable here (redundant, I know)
$obj-> // will code assist the FooBar functions.
Since this is not that great of a syntax, I'm working on having additional support, like with the PDT special #var syntax:
/* #var $obj Foobar */
$obj-> // will code assist the FooBar functions.
Both should be supported in the Studio's next release.
Hope that helps
Related
in a Yii Application in PHPStorm i have the following Code:
$datasource = Yii::app()->someComponent;
PHPStorm is now not able to find the definition of method parameters in autocomplete, if i write
$datasource->aMethod(
Is there a way to tell phpstorm the source in order to have a working autocomplete?, e.g.
// #definition components/SomeComponent.php
$datasource = Yii::app()->someComponent;
Thanks,
markus
You could use a PHP Doc comment to tell PHPStorm which type the var has.
/** #var SomeClassName $datasource */
$datasource = Yii::app()->someComponent;
There's better solution. One which makes PhpStorm able to assign Yii::app()->someComponent to class for entire project.
Put in CAplication's php doc (above class):
/**
* #property Someclass $someComponent.
*/
Solved with one line of code. It works with PhpStorm 9.0, haven't tested earlier versions.
Hello i have a bootloader where i define some basis services like
/** #var $serviceManager Zend\ServiceManager\ServiceManager */
$serviceManager = new ServiceManagerComposite(new ConfigurationComposite($configuration['service_manager']));
But this type of documentation is not available trough my legacy code for hinting, as i found out this will define the variable only on tht one php file. But because i use it as a legacy acess point for my code i need it for the whole php project...
Any sugestions what type of documentation would work with the IDE hinting from Netbeans?
You'd probably need to duplicate at least the first use of $serviceManager with the same #var docblock in each file. If NetBeans is not already resolving scope for you via requires and includes, then this would be the only way to put a context on that "local" variable in the file you're in.
Sangoku is perfectly right!
/* #var $serviceManager Zend\ServiceManager\ServiceManager */
Should do the trick
I am making usage of
/* #var $var Type */
really often for NetBeans can then autocomplete methods and stuff in code.
Still I think its a very useful feature but sometimes I got objects of
classes extending one more class and implementing multiple interfaces.
Or I even got a transitive class hierarchy.
I don't know a way to tell NetBeans that it shall be using autocomplete for
all these interfaces and upper-layer parent classes.
I would like to do so for of course every of these interfaces / classes got
dedicated methods (which are defined somewhere in case of interfaces...)
I tried something like this:
/* #var $var TypeA|\TypeB|\TypeC */
because I saw NetBeans will generate a similar documentation for methods returning
different class objects due a switch/case. But this seems to work only for the
#return notation.
I also tried
/* #var $var TypeA|TypeB */
Also not working...
NetBeans will autocomplete the last told Type in this case but not a combination of both/all told classes.
How can I document so my autocomplete works as desired (a summary of methods of all classes /interfaces I listed)?
regards!
If I understand you correctly, you are asking to chain hint through your PHP code.
The problem is netbeans has no way of knowing what an object actually is; unless you tell it. The solution is to use the #property command in your object decleration to forward type define the objects members , be it a class or interface.
/**
#property classMyClass1 $clsMyClass1
#property classMyClass2 $clsMyClass2
*/
class baseClass{
public $clsMyclass1;
public $clsMyClass2;
public function __construct() {
$this->clsMyClass1 = new classMyClass1();
$this->clsMyClass2 = new classMyClass2();
}
}
$foo = new baseClass();
Now when you type your code in netbeans it will know what hinting to display on your last typed object
$foo->clsMyClass1->
So long as each class has a forward property decleration you can chain as long as you want
$foo->class1->class2->class3->...
The above code would need the autoload() function to load the correct class files....
Hope this helps you!
How might I hint at what $this is in the context of a Magento template, with a DocBlock?
As an example, head.phtml within the template/page/html/ directory is an object of Mage_Page_Block_Html_Head. The method I tried was:
<?php
/**
* #var $this Mage_Page_Block_Html_Head
*/
?>
Unfortunately, it doesn't seem my IDE (NetBeans) is picking up on the hint. So my question is if there is a correct way of doing this so that NetBeans recognizes the hint.
Netbeans should accept it, at least my version 6.9 for
/* #var $this Bar */
does this:
and that is an example with the include scenario (no class around).
Take care to use the single-line - single-asterisk - type-of - commment.
Also take care Netbeans updated the index. As in your case:
NetBeans had to scan for changes in this case, which I would have assumed it would do automatically. [...]. In my case it only periodically scans.
Docblock variable hinting related:
How do I make my PHP IDE understand Dependency Injection Containers?
How can we have autocomplete on property when this one isn't define in the same php file.
for example, with ZF, in the controller we can do
$this->view->voiture = new My_Voiture();
and in the view, we have a variable $this->voiture, but how can i have the autocomplete on it ?
i try /* #var $this->voiture My_voiture */ and no result...
for the moment, my answer is to do in the view
/* #var $voiture My_Voiture */
$voiture = $this->voiture;
but i don't like it. Have you better ?
Documenting the original variable in its original source is actually the best way to go, I think. All other usages of your view in other files should inherit the autocompletion just by documenting it at its one source.
In order to get the autocompletion that I would expect, I would do these things:
In the My_Voiture class, make sure you have docblocks for your variables and your methods. This isn't technically necessary for the autocompletion itself, but it will allow the autocompletion popups to contain much more info that just variables and methods.
In the My_View class, where $voiture is first declared (not used), I would place the #var docblock that identifies its type as My_Voiture. This should be enough to make any usage of its $voiture variable inherit the properties of My_Voiture.
In the My_Controller class, where $view is first declared (not used), I would place the #var docblock that identifies its type as My_View. This should be enough to make any usage of its $view variable inherit the properties of My_View.
Now, in your code file where you are expecting autocompletion on $this->view->voiture -- if it has nothing in it that indicates that $this is a My_Controller object, then Eclipse has nowhere to start when it tries to identify $this (and then all of its properties). I think I've seen some MVC code before where this is prevalent, due to much "dynamic" properties relying on "variable variables" like $$foo.