Our blog

 

Netbeans Autocomplete on Class Properties Using PHPDoc

If you are using netbeans for PHP classes and you have some of your class properties are instances of other objects and you want to get autocomplete working for them, then you might struggle to figure out which PHPDoc syntax to use to get autocomplete working.

Here is the answer:

PHP:
  1. /**
  2. * @property MyObject $myObject
  3. * @property AnotherObject $anotherObject
  4. */
  5. class MyClass{
  6.  
  7.      protected $myObject;
  8.      protected $anotherObject;
  9.      
  10.      public function __construct($myObject, $anotherObject){
  11.          $this->myObject=$myObject;
  12.          $this->anotherObject=$anotherObject;
  13.      }
  14.      
  15.      public function autocomplete(){
  16.          $this->myObject->//autocomplete works here
  17.      }
  18.      
  19. }

More Reading:

3 Comments

Nox
June 8th, 2010

Or using:

/** @var MyObject */
protected $myObject;

 

Matthew T.
March 30th, 2011

What about classes that are more than one level deep. For instance, I use Code Igniter and there are times where you run into this.

/**
* A home-made CI library
* @class sample_library
* @property ao_discount_code $ao_discount_code
*/
class sample_library()
{
public $o_ci;

__construct()
{
$this->o_ci =& get_instance();
$this->o_ci->load->library('form_validation');
$this->o_ci->load->model('ao_discount_code');
}

public function validate_something($s,$s_rule_name)
{
$this->o_ci->ao_discount_code->[ I want autocompletion here]
}
}

 

[...] the right hints in your code, you can jump between classes with Ctrl+Click pretty [...]

 

 

Leave a Reply