@@ -14,6 +14,7 @@ final class ErrorHandler
1414 private $ errorOutputStream ;
1515 private $ hasColorSupport = false ;
1616 private $ logErrors ;
17+ private $ logVariables = true ;
1718 private $ emailCallback ;
1819
1920 private static $ colors = array (
@@ -123,6 +124,16 @@ public function logErrors() : bool
123124 return $ this ->logErrors ;
124125 }
125126
127+ public function setLogVariables (bool $ logVariables )
128+ {
129+ $ this ->logVariables = $ logVariables ;
130+ }
131+
132+ public function logVariables () : bool
133+ {
134+ return $ this ->logVariables ;
135+ }
136+
126137 public function register ()
127138 {
128139 set_error_handler (array ($ this , 'errorHandler ' ), error_reporting ());
@@ -301,18 +312,21 @@ public function emailException(\Throwable $exception)
301312 $ bodyText .= 'Stack trace: ' . "\n\n" . $ this ->purgeTrace ($ currentEx ->getTraceAsString ()) . "\n\n" ;
302313 } while ($ currentEx = $ currentEx ->getPrevious ());
303314
304- if (isset ($ _POST ) and ! empty ($ _POST )) {
305- $ bodyText .= '$_POST = ' . print_r ($ _POST , true ) . PHP_EOL ;
306- }
307315 $ username = null ;
308- if (isset ($ _SESSION ) and ! empty ($ _SESSION )) {
309- $ sessionText = print_r (class_exists (DoctrineDebug::class) ? DoctrineDebug::export ($ _SESSION , 4 ) : $ _SESSION , true );
310- $ bodyText .= '$_SESSION = ' . $ sessionText . PHP_EOL ;
311-
312- $ count = 0 ;
313- $ username = preg_replace ('/.+\[([^\]]+)?username([^\]]+)?\] => ([\w\-\.]+).+/s ' , '\3 ' , $ sessionText , -1 , $ count );
314- if (! isset ($ username [0 ]) or isset ($ username [255 ]) or $ count !== 1 ) {
315- $ username = null ;
316+
317+ if ($ this ->logVariables ()) {
318+ if (isset ($ _POST ) and ! empty ($ _POST )) {
319+ $ bodyText .= '$_POST = ' . print_r ($ _POST , true ) . PHP_EOL ;
320+ }
321+ if (isset ($ _SESSION ) and ! empty ($ _SESSION )) {
322+ $ sessionText = print_r (class_exists (DoctrineDebug::class) ? DoctrineDebug::export ($ _SESSION , 4 ) : $ _SESSION , true );
323+ $ bodyText .= '$_SESSION = ' . $ sessionText . PHP_EOL ;
324+
325+ $ count = 0 ;
326+ $ username = preg_replace ('/.+\[([^\]]+)?username([^\]]+)?\] => ([\w\-\.]+).+/s ' , '\3 ' , $ sessionText , -1 , $ count );
327+ if (! isset ($ username [0 ]) or isset ($ username [255 ]) or $ count !== 1 ) {
328+ $ username = null ;
329+ }
316330 }
317331 }
318332
0 commit comments