Solved

Extend output from logging to include the .php file the line number in that php file variables and values used on that line

Posted on 2014-03-12
3
335 Views
Last Modified: 2014-03-17
I am very much of the opinion that you can't have too much information and either by extending the logging threshold values, outputting more or less data, or by analysis of the output to achieve what I want to see this time.

I would like to trace the path of my  code outputting parameters set or used is this possible and where would I start?

Thanks very much for listening I hope to hear from you

John
0
Comment
Question by:johnecollins
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39923301
Yes, it is possible.  Nobody much does this any more, because object oriented design makes it unnecessary to trace logic - the amounts of code in any method are usually so small that "spaghetti logic" simply does not occur.  But that said, PHP has some tools that can help you do this.

There are the magic constants.  You can print or log these.
http://www.php.net/manual/en/language.constants.predefined.php

Data visualization is available with var_dump(). Especially useful for invisible variables like $_COOKIE and $_SESSION.
http://www.php.net/manual/en/function.var-dump.php

You can log any information you want with error_log()
http://www.php.net/manual/en/function.error-log.php

I have not used it (intentionally) but there is this:
http://www.php.net/manual/en/function.debug-backtrace.php

This article is a little old, but it hits many of the right notes.  Probably XDebug belongs on your short list:
http://coding.smashingmagazine.com/2009/01/20/50-extremely-useful-php-tools/

Since I began PHP before PHP4, I developed my own crude error handlers and tracing process.  In my ancient design, I would set a $debug variable in the script common logic.  And I had a debug() function that I called at various points throughout the script.  If the $debug variable was not set, the function did nothing.  If the $debug variable was set, the debug() function would gather and write a collection of data.  At the end of the script, if the $debug variable was set, the script would conclude by sending me an email message pointing to the file of debugging data.  None of this is necessary any more, since most of my work is OOP.
0
 

Author Closing Comment

by:johnecollins
ID: 39933569
Ray, thanks very much for your help I have had a good read and my knowledge has grown and helped me progress my development

Thanks a lot

John
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39933886
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now