Find missing curly braces in a large PHP file?

I am debugging a 3500 line PHP client file. Including this file causes a PHP Parse error: syntax error, unexpected $end in ... , so I assume that somewhere there is no bracket. Is there a simple tool or method for detecting missing brackets, be it online or in the Komodo IDE that I use?

+6
source share
7 answers

Use consistent and clean tabs. I found it very difficult to skip the closing bracket.

In addition, you kind of dug your grave. What do you code that leads to a 3500 line PHP file?

EDIT: try resetting your code in Notepad ++. I am sure I will highlight the associated closing shape if you click on the opening one, but with large files, I got somewhat unreliable performance with this.

+2
source

another option (similar to notepad ++) is to use Dreamweaver to search for the associated closing tag.
See this link: How do I get Dreamweaver to show closing tags?

in Dreamweaver:
To select the appropriate opening and closing curly brackets, brackets or parentheses, click inside the open or close symbol and click on the “Balance Braces” button on the “Encoding” toolbar (it is immediately below “Select Parent Tag”). Alternatively, use the keyboard shortcut Ctrl + '/ Cmd +'.

+2
source

Komodo Edit has a nice feature that emphasizes that inside curly braces

Ctrl + Alt +]

+1
source

I am just working on a related problem (find the missing square bracket of the array in the JSON object). Therefore, I hope to help.

  $pos=0; $braceCount=0; while( preg_match('~\{|\}~S', $source, $out, PREG_OFFSET_CAPTURE, $pos) ){ if($out[0][0] === '{'){ $braceCount++; if( $braceCount === 1 )$startPos=$out[0][1]; } elseif( $out[0][0] === '}' ){ $braceCount--; if( $braceCount === 0 ){ //echo 'Up to that position:'.$out[0][1].' every thing seems to be ok?<br>'; echo substr($source,$startPos,($out[0][1]+1-$startPos)).'<br>'; } elseif( $braceCount < 0 ){ echo 'To many closing brace right before '.($out[0][1]+1).'<br>'; exit; } } $pos = $out[0][1]+1; } if( $braceCount > 0 ) echo 'Closing brace is missing somewhere.'; 

This drives the source away until a skip match and an error for curly braces appear.

+1
source

Which text editor do you use? I will recommend you use Eclipse, and it will be much easier to find it :), and you can publish your code, and we can help with this :)

0
source

Use the NetBeans IDE for PHP.
http://netbeans.org/features/php/

Checks your syntax and highlights problems among many other nice features that it has. And it's free.

0
source

We really appreciate how smart everyone is! Sometimes it’s better to stick with a tool that a person uses, and that’s what they ask about. I don’t know if you found your answer, but here is what I use.

  • Place the cursor on the opening bracket, then -
  • On Mac: [Command]

or the Edit menu> Balance Braces 3. Result. This will highlight Dreamweaver code between curly braces and help solve the encoding problem.

Hope this helps. Postscript Sometimes you need 3,000 lines of code :)

0
source

Source: https://habr.com/ru/post/908359/


All Articles