如何轻松生成PHP代码的调试语句?

I need to be able to generate debugging statements for my code. For example, here is some code I have:

$this->R->radius_ft  = $this->TC->diameter / 24;
$this->R->TBETA2_rad = $this->D->beta2 / $rad; //Outer angle
$this->R->TBETA1_rad = $this->R->inner_beta1 / $rad; //Inner angle

I need to be able display results of computations so that they can be read by a human.

So far I have been doing this (example showing first line from above only):

$this->R->radius_ft  = $this->TC->diameter / 24;
if (self::DEBUG)
    print("radius_ft({$this->R->radius_ft}) = diameter({$this->TC->diameter}) / 24");

The above print something like radius_ft(1.4583) = diameter(35) / 24 and a few of those lines looks like equations and are nicely traceable when I want to verify things on paper, or if I want to expose the intermediate work of the computations to someone else.

The problem is that it is a pain to construct those debugging statements. I craft them by hand, and usually it is not a problem, but in my current example, there are hundreds of lines of code where this needs to be done. Much pain.

I was wondering if there are facilities in PHP that will allow me to make print-outs of statements showing what each line of code does. Or methods to semi-automate creating the debug lines for me.

I have so far discovered this method to cut down on some of the work .... use Macro facilities of a text editor.

Paste line of code into TextPad (or similar editor that supports macros). Record macro and use Search, Mark and Copy facilities to carefully navigate between special symbols of the variable, such as $, >, and symbols that are not alphanumeric or $, >, etc. while copying and extracting and pasting parts of variable to craft my particular statement.

Exact steps may differ for one's needs. My macro operates on one variable like $this->R->radius_ft with cursor at the start and ends up with something like radius_ft({$this->R->radius_ft}), with cursor a few chars after the end, sometimes coinciding with the next variable to process.

Perhaps same could be done with regular expressions but I like the way Macro does it - I can process a variable and go to the next one and just repeat the macro with a hot key combination. This takes out the most tedious chunk of work for me.


Alternatively - hand the person the code and let them figure it out. Teach them how to read code.