Advanced debugging

I highly recommend the book The Art of Unix Programming by Eric Raymond.

As a result of reading this book, I realized that phppdflib was probably too difficult to hack on. In order for someone to help write code, they would have to overcome three major learning obsticles. They would have to have a good understanding of PHP, a good understanding of PDF, and an understanding of how phppdflib works. I would think that the average person who wants to get involved either already understands PHP or PDF, and there is excellent documentation on both if not, so I'm going to focus on getting over the final hurdle: understanding how this library works internally.

There is very little documentation on the internals, and the source code is sparsely documented. Until now, I've felt the code was obvious in its function, and Raymond's book made me realize why. I believe the most difficult to grasp concept is the structuring of data within the library. Since PHP's arrays are actually hashes, and they can be built dynamically without any preconception of their structures, there is precious little documentation within the code on what these structures are and how they're used. Thus, someone reading the code for the first time sees a number of symbols being juggled around that have no real meaning to him.

My first attempt to solve this issue is to create a debug variable for the library that can be set to capture details of what's occurring during a run.

You will need PHP 4.3 or later to use this feature. All other portions of phppdflib require PHP 4.0.6 or later.

To use it, set $pdf->debug to at least 10, then create your PDF as you normally would. The class variable $pdf->dbs then contains a large string value detailing the array structures that were created for each object painted to the PDF. At first glance, it may seem that simply using print_r() to view the $pdf->objects variable would be just as easy, but the debug method adds some additional chatter to help understand what's going on.

Additionally, setting $pdf->debug to at least 20 causes details of the ->generate() process to be stored in $pdf->dbs as well. This has additional use in understanding the library, as well as being helpful to someone who is trying to learn PDF for the first time.

There is more that should be done with this. Additional debug levels should be defined and additional debug traps peppered throughout the code to capture activity as it occurs. This would help a new hacker understand both the structure of data and the flow of program logic within the class.

Hopefully this will generate more interest in the library, and incite development assistance.