Sublime Forum

Code Folding and PHP HEREDOC

#1

I use a lot of HEREDOC statements in my PHP and noticed that this seems to severely get in the way of code folding in Sublime. E.g. try folding the example function, or the “then” portion of the if statement in this code to see what I mean:

<?php function example($a) { if (1) { echo $a; $str = <<<HEREDOC line1 line2 HEREDOC; echo $a; } else { echo $a; echo $a; } }

In reading this recent post (https://forum.sublimetext.com/t/confused-code-folding/7899/2), it sounds like the folding logic is based on indent levels, which certainly doesn’t work with PHP’s HEREDOC requirement of having the ending marker in column 1. See http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc.

Are there any workarounds in Sublime for this? Am I doing something wrong here?

1 Like

#2

I googled “sublime folding heredoc” and found this “thread”
seems like if there’s a matching bracket, it should fold based on the matching bracket.

0 Likes

#3

I’m troubled with the same problem, not only heredoc, even if I bad comment like this:

function() doNothing($forever) { usleep($forever); // bad comment }
will break the code folding. I think this is too stupid.

searched a little and found one package called syntaxfold seems to fix this, but tried with no luck

if you found the solution, plz let me know.

0 Likes

#4

The same problem happens with shell heredoc:

0 Likes

#5
1 Like