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!

1
  • Have you tried loading the application in an IDE and searching for some substrings of the unexpectedly outputted strings in the code? Commented Sep 26, 2018 at 15:14

2 Answers 2

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); 
?>
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.