OM2 Posted August 17, 2011 Share Posted August 17, 2011 If I have a file that is full of functions that do 'things', I assume if I wanted to debug or test that it would necessarily work if I try to echo from inside of a function? In that case, what do I do if I want to test or debug? The only thing I can think of is creating a file and writing to it But is this the only way Could I write to a log file - without going to the bother of opening and closing a file or something? Thanks OM Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/ Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 What? You can echo inside of a function in order to debug or trace Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258372 Share on other sites More sharing options...
OM2 Posted August 17, 2011 Author Share Posted August 17, 2011 Maybe, I'm doing something wrong Are you saying that if I echo ANYWHERE, as long as that part of code is run, and echo will ALWAYS output to the screen? Are there no circumstances where this won't be true? I have a Flash file that uploads files and then runs a php script In this php script, I have put echo statements next to code that I know 100% it runs - but I get no output Am I doing something wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258387 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Perhaps a header redirect before the echo gets a chance to run? Is the file being called by the flash application rather than the browser? Similar to an AJAX call? If so, you'll have to find a way to get the flash application to give you the text returned by the script. Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258389 Share on other sites More sharing options...
OM2 Posted August 17, 2011 Author Share Posted August 17, 2011 Perhaps a header redirect before the echo gets a chance to run? Is the file being called by the flash application rather than the browser? Similar to an AJAX call? If so, you'll have to find a way to get the flash application to give you the text returned by the script. yes being called by flash file forgetting flash for a second, if an echo is done, will it ALWAYS output to the browser? thanks Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258393 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Assuming the browser is executing the script, it should output to the browser (though client-side configurations can affect this - plugins like adblock will hide pre-defined lists of images etc.) There are functions that can prevent this however, like ob_start() and ob_end_clean(). If you haven't coded any output buffering into your script though, I really wouldn't be worried. Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258665 Share on other sites More sharing options...
OM2 Posted August 17, 2011 Author Share Posted August 17, 2011 thanks that's really helpful i was going through some code a freelancer coded for me and they used ob_start() i looked up on php.net, but couldn't get my head round what it was supposed to do and why one might use it? Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258671 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Here's a read that tells you everything you need to know about how PHP handles outputs http://phpadvent.org/2010/output-buffering-by-nicholas-sloan I don't really like using output buffering. I don't ever see a need for it myself with the rare exception of a pesky function that outputs directly rather than returning a value. Just my personal opinion - some good programmers use it, other good programmers don't. Just about anything you can do with output buffering can be done without it. Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258689 Share on other sites More sharing options...
OM2 Posted August 18, 2011 Author Share Posted August 18, 2011 hey: that's a great article i have a good understanding now and can see the benefits of using it's really annoying creating a damn string and continually concatinating to i've book marked the site as well - its got a lot of useful articles thanks! Quote Link to comment https://forums.phpfreaks.com/topic/244970-how-to-debug-a-file-that-doesnt-output/#findComment-1258848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.