2

When I run php someScript.php I get some expected output and some unexpected strings. They look like debugging strings and were probably placed there during development. The file is a part of a larger framework and can include other files that can further require others.

I have no idea which function (echo, print, var_dump, write, ...) is being used to output the (unwanted) strings.

How can I find a file & row number of a place where a (dynamically generated) string is being outputted to stdout.

thx!

  • Have you tried loading the application in an IDE and searching for some substrings of the unexpectedly outputted strings in the code? – nl-x Sep 26 '18 at 15:14

2 Answers2

2

It's a bit ugly but you could try to mess with the output buffers. The following approach seems to work for me:

<?php
$locations = [];
ob_start(function($buffer) {
  global $locations;
  $locations[] = debug_backtrace();
  return $buffer;
}, 1);

// Your code with output here.

// $locations should contain the information now
print_r($locations); 
?>
likle
  • 1,717
  • 8
  • 10
0

You should be able to tell from the structure of the output if it's var_dump, dd, or if it's a more basic echo. If you search the codebase for echo, are there actually that many of them?

You can try using xdebug to start stepping through the code line by line, and figure out where it's being printed. If the string being printed truly has no static text you can grep the codebase for, this is where I'd start.

Jessica
  • 7,075
  • 28
  • 39