Archive for October, 2009

tips for php coding in netbeans


I’ve switched from Vim to netbeans in the past 9 months or so – I’ve been using Vim for 5+ years before that and finding an editor to beat it wasn’t easy. Main aim was to get better code completion, plus whichever editor I used had to have ‘hippie search‘  – this speeds up coding no end. Tried eclipse PDT along the way but found that too slow.

Ultimately netbeans persuaded me to convert. Here are some tips for using it:

General tips

  • Use at least 6.8 beta version of netbeans – there are performance improvements for code completion which increase code completion a lot. If you’ve tried 6.7/6.5 – try again with the 6.8 beta+, especially with large projects.
  • Enable hippie search – The default keys are ctrl+k and ctrl+shift+k – If you’re a Vim person, change these to ctrl+p and ctrl+n. The ‘Actions’ in the keymap editor are ‘Next matching word’ and ‘Previous matching word’
  • Initiate code completion manually – use ctrl+space (default) I find the auto code completion popup just gets in the way. YMMV.
  • Use Navigate menu – this allows you to find files/classes/functions/methods in your code almost instantly
  • phpdoc your code: this allows code completion to work in places it otherwise could not


  • Ignore ‘test’ directories – make sure you ignore certain dirs in symfony. This makes code completion ignore classes under those directories.  I have problems with it picking up classes not in our project e.g. sfContext can get confused with sfContextMock from the tests.
  • Symfony is supported in netbeans 6.8M2+ see

netbeans php code completion speed


If you’ve suffered slow netbeans code completion speeds in the past, you should look at the latest dev build

Code completion is much quicker – instead of the 4-5 seconds it used to take, it’s now almost instant on a large php project with approx. 12,000 files (including symfony framework)

Add MAXLENGTH attribute to sfWidgetFormInput


One oversight of symfony is that it does not add the MAXLENGTH attribute to the sfWidgetFormInput/sfWidgetFormInputText widget even though it knows the max length for a validator. For Propel (Doctrine too?), symfony 1.2/1.3 allows you to override the setup in BaseFormPropel in lib\form\BaseFormPropel.class.php. Overriding setup() allows you to add the MAXLENGTH attribute based on the validator.

public function setup() {
  foreach ($this->getWidgetSchema()->getFields() as $name => $widget)
    $classname = get_class($widget);
    if ($classname == 'sfWidgetFormInputText') {
      if (($val = $this->getValidator($name)) && ($len = $val->getOption('max_length'))) {
        $widget->setAttribute('maxlength', $len);