12

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.
HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
snakile
  • 52,936
  • 62
  • 169
  • 241
  • No. Using ` – snakile Aug 29 '11 at 08:58
  • @Marek: Thanks, I've edited the question and added more info. – snakile Aug 29 '11 at 09:11
  • please check this discussion, if it is your case. http://netbeans.org/projects/www/lists/netcat/archive/2011-07/message/77 – Marek Sebera Aug 29 '11 at 09:15
  • 1
    are you able to duplicate behavior by moving contents of file to another one? or can you provide a sample use-case file where code folding doesn't work? – Marek Sebera Aug 29 '11 at 13:12
  • 1
    @Marek: No, I can't duplicate the behavior. I've copied the code to a new file, and the new file does have these code folds I was looking for. In other words, my real problem is solved. However, the mystery hasn't been solved yet, so I do not delete the question. – snakile Aug 29 '11 at 19:14
  • I expect something like **Wrong encoded character** (non-UTF8 or so), but because we cannot replicate behavior/issue i recommend you to close the question (it is common behavior when using bugzilla and similar systems) – Marek Sebera Aug 29 '11 at 19:17
  • 1
    @Marek: OK, I agree. I cast vote to close. – snakile Aug 29 '11 at 19:23
  • @snakile Same thing for me. Copied a file behaving the same way and presto! It works. Seems that is the real solution here. Tried just about all the other suggestions here too. – The Thirsty Ape Jun 14 '13 at 17:11
  • I can not speak directly for NetBeans, but I know in Zend Studio and other applications like TextMate, if the tabbing is not correct (identical for start and end tags), it will not fold. – Marty Aug 29 '11 at 18:46
  • This problem still persists in netbeans 8.0.2 - php / js / html /css editing – MarcoZen May 03 '15 at 07:00

9 Answers9

5

@ 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.

Dave
  • 51
  • 1
  • 2
4

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.

m_korena
  • 161
  • 1
  • 12
0

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.

tomo7
  • 451
  • 7
  • 6
0

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

o0omycomputero0o
  • 3,316
  • 4
  • 31
  • 45
0

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.

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88
0

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.

Joe T.
  • 43
  • 6
0

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>
Jeff
  • 1
  • 1
0

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

sudhir chauhan
  • 862
  • 7
  • 3
0

This is an old thread, but I am now using NetBeans IDE 13, and I just discovered that if your JavaScript file has the word "config" in the name of it, code folding does not work. I can copy every line of code from SV_Config.js into a new file named newfile.js and code folding will work in the 2nd file, but not in the 1st one. If I copy the code into another new file config.js, again code folding will not work in the 3rd file. Weird huh?

Reese
  • 1
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34142707) – Eyad Mohammed Osama Apr 04 '23 at 11:26
  • Looks like more suitable for a comment – Anton Tokmakov Apr 11 '23 at 05:20