Question

I'm using the NetBeans IDE. Normally, every PHP file in my project has code folds:

code folds appear

However, one PHP file in my project doesn't have code folds:

code folds do not appear

The file has no syntax errors. I've tried restarting NetBeans and reopening the project and the folds still do not appear. What could it be?

More info:

  • I'm using NetBeans IDE 7.0.1.
  • The file's extension is .php like all the PHP files in my project.
  • On another file which has the same content exactly, code folds appear.
Was it helpful?

Solution

Follow the following steps:

1) open netbeans 2) select tool => options 3) select Editor tab and General sub tab 4) and check code fold check box

Find attached image for detail.


enter image description here

OTHER TIPS

@ sudhir chauhan: If code folds wasn't already selected the other php files would not have folds alredy.

This is a known bug with Netbeans that is very annoying and happens occasionally to me as well when editing PHP. The only solution is to save the file, close the Netbeans IDE and re-open Netbeans.

Also sometimes you unfold code and click to refold and you cant.. to resolve this related issue just click on a line outside the fold (ie. the function above) then click on the "-" to refold the code.

This problem persists in Netbeans 7.2.1, not only with PHP, but also with java code, the way that works for me is to uncheck [Use code fold:] as described in o0omycomputero0o's answer, apply changes by clicking OK, then recheck [Use code folding:], and click OK, it sort of re-validates the code folds to the expected state, No IDE reload needed.

Something I just found that was significant for me personally:

if you have comments like this <!-------- ------>

i.e. more than just 2 dashes <!-- --> then netbeans seems to get confused.

Remove the extra dashes and code folding appears magically.

If it happend in netbean 8, you can goto Tool > Option > Editor > Folding, choose language as PHP(or whatever language you found that not folding code correctly), uncheck "Enable code folding", click OK. Then goto Tool > Option > Editor > Folding and check "Enable code folding", click OK, then it may work :). enter image description here

If you are working on an .htmlfile and you are facing this issues, please check if you have any errors in the documents, Since Netbeans seems to disable code folding if it finds syntax errors in html tags.

In my case, few of the anchor tags were being closed by the wrong closing tags.

wrong >>    <h5><a href="mailto:gracias@email.com">Mucho Grassy Ass<a/></h5>

right >>    <h5><a href="mailto:gracias@email.com">Mucho Grassy Ass</a></h5>

After correcting the above error, the code folding was correctly appearing.

Just noticed that this seems to impact files that have a . in their name, because Netbeans does not automatically add the .php extension. If you are using class.{classname} as the file name, outlining will not appear, because the file will have .{classname} as the extension instead of .php.

To fix, make sure you type .php if you are using class.{classname} as the filename when creating a new file.

The problem still exists in NetBeans 11.2 and seems to be caused by HTML inclusion in the code.

Reproducing the problem: Both fold tags don't work. This can be caused by simply deleting and replacing the right p in the <?php following 'Some HTML'. If you remove the ?> <p>Some HTML</p> <?php and paste it back the folds work again.

<?php
// <editor-fold defaultstate="collapsed" desc="HTML in php function"> 
function test1() {
  // some PHP code
  ?>
  <p>Some HTML</p>
  <?php
  // Some more PHP
}
// </editor-fold> 
// <editor-fold defaultstate="collapsed" desc="More HTML"> 

function test2($url, $alt) {
  // some PHP code
  if (strlen($url)) {
    ?>
    <div class="divProductTableImage">
      <img class="imgProductTableImage" 
           src="<?php echo $url; ?>"
           alt="<?php echo $alt; ?>" />
    </div>
    <?php
  }
}
// </editor-fold>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top