html_vardump: printf on steroids

html_vardump()

So how exactly do you debug you PHP scripts? I’m not expert on this, but I find it inconvenient trying to debug an interpreted file living in a daemon process. I mean, with a real program, you can attach to it with something like GDB. But with PHP, I find myself resorting back to the old printf school of debugging.

html_vardump() is a slight improvement for dumping out data structures. It is more-or-less the same as PHP’s vardump but with two modifications. First, all of the output is run through htmlentities() and addcslashes() so that everything will print in a web page. Second, you can decide whether or not you want html_vardump() to print everything or simply return a string which can be printed wherever you like. Not printing is the default.

Here’s a simple example of using html_vardump():

$image = "mypic.jpeg";
$exif  = read_exif_data ($image);
$vardump = html_vardump ($exif, 0);
echo $vardump;

And here is what the output from a real picture looks like:

  array(64) =>
[FileName] =>
string(17) =>
"20010601-0001.jpg"
[FileDateTime] =>
integer(991436204)
[FileSize] =>
integer(307155)
[FileType] =>
integer(2)
[MimeType] =>
string(10) =>
"image/jpeg"
[SectionsFound] =>
string(50) =>
"ANY_TAG, IFD0, THUMBNAIL, EXIF, INTEROP, MAKERNOTE"
[COMPUTED] =>
array(11) =>
[html] =>
string(25) =>
"width="1280" height="960""
[Height] =>
integer(960)
[Width] =>
integer(1280)
[IsColor] =>
integer(1)
[ByteOrderMotorola] =>
integer(0)
[CCDWidth] =>
string(3) =>
"5mm"
[ExposureTime] =>
string(14) =>
"0.016 s (1/64)"
[ApertureFNumber] =>
string(5) =>
"f/3.6"
[Copyright] =>
string(10) =>
"          "
[Thumbnail.FileType] =>
integer(2)
[Thumbnail.MimeType] =>
string(10) =>
"image/jpeg"
[Make] =>
string(8) =>
"FUJIFILM"
[Model] =>
string(15) =>
"FinePix1400Zoom"
[Orientation] =>
integer(1)
[XResolution] =>
string(4) =>
"72/1"
[YResolution] =>
string(4) =>
"72/1"
[ResolutionUnit] =>
integer(2)
[Software] =>
string(38) =>
"Digital Camera FinePix1400Zoom Ver1.00"
[DateTime] =>
string(19) =>
"2001:06:01 17:56:44"
[YCbCrPositioning] =>
integer(2)
[Copyright] =>
string(10) =>
"          "
[Exif_IFD_Pointer] =>
integer(276)
[THUMBNAIL] =>
array(8) =>
[Compression] =>
integer(6)
[Orientation] =>
integer(1)
[XResolution] =>
string(4) =>
"72/1"
[YResolution] =>
string(4) =>
"72/1"
[ResolutionUnit] =>
integer(2)
[JPEGInterchangeFormat] =>
integer(1100)
[JPEGInterchangeFormatLength] =>
integer(5700)
[YCbCrPositioning] =>
integer(2)
[FNumber] =>
string(5) =>
"36/10"
[ExposureProgram] =>
integer(2)
[ISOSpeedRatings] =>
integer(125)
[ExifVersion] =>
string(4) =>
"0210"
[DateTimeOriginal] =>
string(19) =>
"2001:06:01 17:56:44"
[DateTimeDigitized] =>
string(19) =>
"2001:06:01 17:56:44"
[ComponentsConfiguration] =>
string(4) =>
"\001\002\003\000"
[CompressedBitsPerPixel] =>
string(3) =>
"2/1"
[ShutterSpeedValue] =>
string(5) =>
"60/10"
[ApertureValue] =>
string(5) =>
"37/10"
[BrightnessValue] =>
string(6) =>
"-13/10"
[ExposureBiasValue] =>
string(4) =>
"0/10"
[MaxApertureValue] =>
string(5) =>
"37/10"
[MeteringMode] =>
integer(5)
[Flash] =>
integer(1)
[FocalLength] =>
string(6) =>
"180/10"
[MakerNote] =>
string(214) =>
"FUJIFILM\f\000\000\000\017\000\000\000\a\000\004\000\000\0000130\000\020\002\ ...
[FlashPixVersion] =>
string(4) =>
"0100"
[ColorSpace] =>
integer(1)
[ExifImageWidth] =>
integer(1280)
[ExifImageLength] =>
integer(960)
[InteroperabilityOffset] =>
integer(952)
[FocalPlaneXResolution] =>
string(6) =>
"2453/1"
[FocalPlaneYResolution] =>
string(6) =>
"2453/1"
[FocalPlaneResolutionUnit] =>
integer(3)
[SensingMethod] =>
integer(2)
[FileSource] =>
string(1) =>
"\003"
[SceneType] =>
string(1) =>
"\001"
[InterOperabilityIndex] =>
string(3) =>
"R98"
[InterOperabilityVersion] =>
string(4) =>
"0100"
[Version] =>
string(4) =>
"0130"
[Quality] =>
string(7) =>
"NORMAL "
[Sharpness] =>
integer(3)
[WhiteBalance] =>
integer(0)
[FlashMode] =>
integer(3)
[FlashStrength] =>
string(4) =>
"0/10"
[Macro] =>
integer(0)
[FocusMode] =>
integer(0)
[SlowSync] =>
integer(0)
[PictureMode] =>
integer(0)
[ContTake] =>
integer(0)
[UndefinedTag:0x1200] =>
integer(0)
[BlurWarning] =>
integer(0)
[FocusWarning] =>
integer(1)
[AEWarning ] =>
integer(1)

I originally wrote html_vardump() in order to debug class.rFastTemplate.php so I could see exactly what was inside that big class variable I was creating. So, yes, it will handle class variables, too. The file containing html_vardump() has a couple of other functions I’ve been working on (off and on). Feel free to discard them if you don’t like them.