How to block php debugging output in svn?

I would like to block the debugging functions var_dump, print_r, etc... from being sent to the repo so that QA can go to things and not report errors like "There is a huge block of text on all pages!"

I tried regex (not a good idea ... presumably).

I also tried token_get_all , but for some reason, it returns T_STRING for each of the debugging functions, which I think will work, but it seems weird ...

Is there a third best way?

+8
debugging php svn pre-commit-hook
source share
4 answers

Based on my new understanding, this is what I have:

 $debug_functions = array('print_r', 'var_dump', 'var_export'); foreach($files as $file=>$ext){ $file_contents = file_get_contents($file); //break the content into tokens $tokens = token_get_all($file_contents); foreach($tokens as $t){ //if the token id is an int (sometimes it isn't) if(is_int($t[0])){ //if it matches our debug stuff... if($t[0] == T_STRING && (in_array($t[1], $debug_functions) || preg_match('/xdebug_.*?/', $t[1]))){ echo 'Debug output '. $t[1] . ' found on line '. $t[2] . PHP_EOL; } } } } 
0
source share

This may not be the answer you are looking for, but I highly recommend deleting your entire print_r, var_dump file, etc. from your code.

  • Save your code permanently.
  • Those tags are for debugging purposes only.
  • when you commit, you must make sure that everything works as expected. Changing the commit code or having a different code on your computer than in real time provides errors and problems.

Therefore, remove those tags, do not store them in your code, even on the local computer .

0
source share

You can write sniff PHP_CodeSniffer and force SVN to execute it as a prefix hook. This would reject the adoption of such code.

0
source share

An alternative method does not use var_dump functions and related functions at all. Encoding guidelines include

0
source share

All Articles