PHP #region for code folding?

Is there an equivilent of c#'s #region in PHP?


No, there's nothing directly in the language.

But every decent editors allow some kind of markup to allow this.

For example in Netbeans :

// <editor-fold defaultstate="collapsed" desc="user-description">
  ...any code...
// </editor-fold>

This syntax also works in all the Intellij IDEA editor family, see http://blog.jetbrains.com/webide/2012/03/new-in-4-0-custom-code-folding-regions/

You can also emulate the feature in Eclipse via a plugin : Code folding plugin for Eclipse?

Visual Studio Code includes it since version 1.19 :

#region user description
...any code...
#endregion

No.

The thing is, C# is sort of designed to be written by only one IDE, because Microsoft need you to always use their tools. So, built into the language (sort of) are things that affect the IDE.

PHP, on the other hand, is just a language. It's not supposed to have a symbiotic relationship with some specific editor, so it doesn't. So, no, it has nothing to control your editor.

Still, all proper programming text editors support folding class definitions, function definitions, and most scope blocks. Some editors may allow certain extensions to go beyond this.


As everybody has said before, the #region in .Net is actually a Visual Studio feature, not a C# one, but the fact that the C# grammar supports the syntax, allows its usage by any IDE that wants to implement it. Since in PHP, the '#' character is also used for comments, the same can be done by the IDEs. In fact, JetBrains' PhpStorm does it: https://blog.jetbrains.com/phpstorm/2012/03/new-in-4-0-custom-code-folding-regions/